{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\".\\\\diyLogo.png\" alt=\"some_text\">\n",
    "<h1> 第三讲 程序设计基础</h1>\n",
    "<a id=backup></a>\n",
    "<H2>目录</H2>  \n",
    "\n",
    "[3.1 组合数据类型概述](#Section1)  \n",
    "[3.2 序列类型](#Section2)  \n",
    "[3.3 集合类型](#Section3)     \n",
    "[3.4 映射类型](#Section4)  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id = Section1> </a>\n",
    "## 3.1 组合数据类型概述\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id = Section2> </a>\n",
    "## 3.2 序列类型\n",
    "### 字符串\n",
    "### 元组\n",
    "### 列表\n",
    "\n",
    "<p><a href=\"https://yanghailin.blog.csdn.net/article/details/81126087?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-5.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-5.no_search_link\">\n",
    "this is example of python</a></p"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2.1字符串运算\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a + b 输出结果： HelloPython\n",
      "a * 2 输出结果： HelloHello\n",
      "**************************************************\n",
      "a[1] 输出结果： e\n",
      "a[1:4] 输出结果： ell\n",
      "H 在变量 a 中\n",
      "M 不在变量 a 中\n",
      "\\n\n",
      "\\n\n"
     ]
    }
   ],
   "source": [
    "a = \"Hello\"\n",
    "b = \"Python\"\n",
    " \n",
    "print(\"a + b 输出结果：\", a + b)\n",
    "print(\"a * 2 输出结果：\", a * 2)\n",
    "print(\"*\"*50)\n",
    "print(\"a[1] 输出结果：\", a[1])\n",
    "print(\"a[1:4] 输出结果：\", a[1:4])\n",
    "# in \n",
    "if( \"H\" in a) :\n",
    "    print(\"H 在变量 a 中\")\n",
    "else :\n",
    "    print(\"H 不在变量 a 中\")\n",
    "#not in \n",
    "if( \"M\" not in a) :\n",
    "    print(\"M 不在变量 a 中\")\n",
    "else :\n",
    "    print(\"M 在变量 a 中\")\n",
    "# r R 直接打印字符串 \n",
    "print (r'\\n')\n",
    "print (R'\\n')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2.2元组\n",
    "Python 的元组与列表类似，不同之处在于元组的元素不能修改,可以合并。\n",
    "\n",
    "元组使用小括号 ( )，列表使用方括号 [ ]。\n",
    "\n",
    "元组创建很简单，只需要在括号中添加元素，并使用逗号隔开即可。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('Google', 'Runoob', 1997, 2000) \n",
      " tup2 \n",
      " ('a', 'b', 'c', 'd') \n",
      " <class 'tuple'>\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'Google'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tup1 = ('Google', 'Runoob', 1997, 2000)\n",
    "tup2 = (1, 2, 3, 4, 5 )\n",
    "tup3 = \"a\", \"b\", \"c\", \"d\"   #  不需要括号也可以\n",
    "type(tup3)\n",
    "print(tup1,\"\\n\",\"tup2\",\"\\n\",tup3,\"\\n\",type(tup3))\n",
    "tup1[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2448321434544\n",
      "2448321266176\n"
     ]
    }
   ],
   "source": [
    "print(id(tup1))\n",
    "tup1=1,2,3\n",
    "print(id(tup1))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2.3列表\n",
    "序列是 Python 中最基本的数据结构。\n",
    "\n",
    "序列中的每个值都有对应的位置值，称之为索引，第一个索引是 0，第二个索引是 1，依此类推。\n",
    "\n",
    "Python 有 6 个序列的内置类型，但最常见的是列表和元组。\n",
    "\n",
    "列表都可以进行的操作包括索引，切片，加，乘，检查成员。\n",
    "\n",
    "此外，Python 已经内置确定序列的长度以及确定最大和最小的元素的方法。\n",
    "\n",
    "列表是最常用的 Python 数据类型，它可以作为一个方括号内的逗号分隔值出现。\n",
    "\n",
    "列表的数据项不需要具有相同的类型\n",
    "\n",
    "创建一个列表，只要把逗号分隔的不同的数据项使用方括号括起来即可。如下所示："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "red\n",
      "white\n",
      "black\n"
     ]
    }
   ],
   "source": [
    "list1 = ['red', 'green', 'blue', 'yellow', 'white', 'black']\n",
    "print( list1[0] )\n",
    "print( list1[-2] )\n",
    "print( list1[-1] )\n",
    "list1[0]='lightred'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "list[0]:  Google\n",
      "list[0:4]:  ['Google', 'Runoob', 'Zhihu', 'Taobao', 'Wiki']\n"
     ]
    }
   ],
   "source": [
    "list = ['Google', 'Runoob', \"Zhihu\", \"Taobao\", \"Wiki\"]\n",
    " \n",
    "# 读取第二位\n",
    "print (\"list[0]: \", list[0])\n",
    "# 从第二位开始（包含）截取到倒数第二位（不包含）\n",
    "print (\"list[0:4]: \", list[0:5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "更新后的第三个元素为 :  ['x', 'a', 2001, 'a', 't']\n",
      "更新后的列表 :  ['x', 'a', 2001, 'a', 't', 'Baidu']\n"
     ]
    }
   ],
   "source": [
    "#\n",
    "list[2] = 2001\n",
    "print (\"更新后的第三个元素为 : \", list)\n",
    " \n",
    "list.append('Baidu')\n",
    "print (\"更新后的列表 : \", list)\n",
    "\n",
    "list[:]=''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n"
     ]
    }
   ],
   "source": [
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#删除元素\n",
    "del list[2]\n",
    "print (\"删除第三个元素 : \", list)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Python列表函数&方法\n",
    "Python包含以下函数:\n",
    "<table><tr>\n",
    "<th style=\"width:5%\">序号</th><th style=\"width:95%\">函数</th></tr>\n",
    "\n",
    "<tr><td>1</td><td><a href=\"python3-att-list-len.html\">len(list)</a><br>列表元素个数</td></tr>\n",
    "<tr><td>2</td><td><a href=\"python3-att-list-max.html\">max(list)</a><br>返回列表元素最大值</td></tr>\n",
    "<tr><td>3</td><td><a href=\"python3-att-list-min.html\">min(list)</a><br>返回列表元素最小值</td></tr>\n",
    "<tr><td>4</td><td><a href=\"python3-att-list-list.html\">list(seq)</a><br>将元组转换为列表</td></tr>\n",
    "</table>\n",
    "\n",
    "Python包含以下方法:\n",
    "<table><tr>\n",
    "<th style=\"width:5%\">序号</th><th style=\"width:95%\">方法</th></tr>\n",
    "<tr><td>1</td><td><a href=\"python3-att-list-append.html\">list.append(obj)</a><br>在列表末尾添加新的对象</td></tr>\n",
    "<tr><td>2</td><td><a href=\"python3-att-list-count.html\">list.count(obj)</a><br>统计某个元素在列表中出现的次数</td></tr>\n",
    "<tr><td>3</td><td><a href=\"python3-att-list-extend.html\">list.extend(seq)</a><br>在列表末尾一次性追加另一个序列中的多个值（用新列表扩展原来的列表）</td></tr>\n",
    "<tr><td>4</td><td><a href=\"python3-att-list-index.html\">list.index(obj)</a><br>从列表中找出某个值第一个匹配项的索引位置</td></tr>\n",
    "<tr><td>5</td><td><a href=\"python3-att-list-insert.html\">list.insert(index, obj)</a><br>将对象插入列表</td></tr>\n",
    "<tr><td>6</td><td><a href=\"python3-att-list-pop.html\">list.pop([index=-1])</a><br>移除列表中的一个元素（默认最后一个元素），并且返回该元素的值</td></tr>\n",
    "<tr><td>7</td><td><a href=\"python3-att-list-remove.html\">list.remove(obj)</a><br>移除列表中某个值的第一个匹配项</td></tr>\n",
    "<tr><td>8</td><td><a href=\"python3-att-list-reverse.html\">list.reverse()</a><br>反向列表中元素</td></tr>\n",
    "<tr><td>9</td><td><a href=\"python3-att-list-sort.html\">\tlist.sort( key=None, reverse=False)</a><br>对原列表进行排序</td></tr>\n",
    "<tr><td>10</td><td><a href=\"python3-att-list-clear.html\">list.clear()</a><br>清空列表</td></tr>\n",
    "<tr><td>11</td><td><a href=\"python3-att-list-copy.html\">list.copy()</a><br>复制列表</td></tr>\n",
    "</table>\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mitsubishi', 'Ford', 'BMW', 'VW']\n"
     ]
    }
   ],
   "source": [
    "# A function that returns the length of the value:\n",
    "def myFunc(e):\n",
    "  return len(e)\n",
    "cars = ['Ford', 'Mitsubishi', 'BMW', 'VW']\n",
    "cars.sort(reverse=True, key=myFunc)\n",
    "print(cars)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mitsubishi', 'Ford', 'BMW']\n"
     ]
    }
   ],
   "source": [
    "cars.pop()\n",
    "print(cars)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id=Section3></a>\n",
    "## 3.3 集合类型\n",
    "集合（set）是一个无序的不重复元素序列。\n",
    "\n",
    "可以使用大括号 { } 或者 set() 函数创建集合，注意：创建一个空集合必须用 set() 而不是 { }，因为 { } 是用来创建一个空字典。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.3.1基本操作："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "'set' object is not subscriptable",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[4], line 3\u001b[0m\n\u001b[0;32m      1\u001b[0m basket \u001b[38;5;241m=\u001b[39m {\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mapple\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124morange\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mapple\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mpear\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124morange\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbanana\u001b[39m\u001b[38;5;124m'\u001b[39m}\n\u001b[0;32m      2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mlen\u001b[39m(basket))                      \u001b[38;5;66;03m# 这里演示的是去重功能\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[43mbasket\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\n",
      "\u001b[1;31mTypeError\u001b[0m: 'set' object is not subscriptable"
     ]
    }
   ],
   "source": [
    "basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}\n",
    "print(len(basket))                      # 这里演示的是去重功能\n",
    "basket[0] #不能索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "{'orange', 'banana', 'pear', 'apple'}\n",
    "'orange' in basket                 # 快速判断元素是否在集合内"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'crabgrass' in basket"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a= {'d', 'c', 'r', 'a', 'b'}\n",
      "b= {'z', 'm', 'c', 'l', 'a'}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'b', 'd', 'r'}"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 下面展示两个集合间的运算.\n",
    "a = set('abracadabra')\n",
    "b = set('alacazam')\n",
    "print('a=',a)\n",
    "print('b=',b)\n",
    "# 集合a中包含而集合b中不包含的元素                                 \n",
    "a - b                              "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'a', 'b', 'c', 'd', 'l', 'm', 'r', 'z'}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 集合a或b中包含的所有元素（并集）\n",
    "a | b                              "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'a', 'c'}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 集合a和b中都包含了的元素(交集)\n",
    "a & b                              "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'b', 'd', 'l', 'm', 'r', 'z'}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 不同时包含于a和b的元素（交集的补集）\n",
    "a ^ b                              "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'d', 'r'}\n"
     ]
    }
   ],
   "source": [
    "#类似列表推导式，同样集合支持集合推导式(Set comprehension):\n",
    "a = {x  for x in 'abracadabra' \n",
    "              if x not in 'abc'}\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.3.2集合运算\n",
    "\n",
    "<table><tr>\n",
    "<th>方法</th>\n",
    "<th>描述</th>\n",
    "</tr>\n",
    "<tr><td><a href=\"ref-set-add.html\" target=\"_blank\" rel=\"noopener noreferrer\">add()</a></td><td>为集合添加元素</td></tr>\n",
    "<tr><td><a href=\"ref-set-clear.html\" target=\"_blank\" rel=\"noopener noreferrer\">clear()</a></td><td>移除集合中的所有元素</td></tr>\n",
    "<tr><td><a href=\"ref-set-copy.html\" target=\"_blank\" rel=\"noopener noreferrer\">copy()</a></td><td>拷贝一个集合</td></tr>\n",
    "  <tr>\n",
    "    <td><a href=\"ref-set-difference.html\" target=\"_blank\" rel=\"noopener noreferrer\">difference()</a></td><td>返回多个集合的差集</td>\n",
    "  </tr>\n",
    "  <tr>\n",
    "    <td><a href=\"ref-set-difference_update.html\" target=\"_blank\" rel=\"noopener noreferrer\">difference_update()</a></td><td>移除集合中的元素，该元素在指定的集合也存在。</td>\n",
    "  </tr>\n",
    "<tr><td><a href=\"ref-set-discard.html\" target=\"_blank\" rel=\"noopener noreferrer\">discard()</a></td><td>删除集合中指定的元素</td></tr>\n",
    "  <tr>\n",
    "    <td><a href=\"ref-set-intersection.html\" target=\"_blank\" rel=\"noopener noreferrer\">intersection()</a></td><td>返回集合的交集</td>\n",
    "  </tr>\n",
    "<tr><td><a href=\"ref-set-intersection_update.html\" target=\"_blank\" rel=\"noopener noreferrer\">intersection_update()</a></td><td>\n",
    "  返回集合的交集。</td></tr>\n",
    "  <tr>\n",
    "    <td><a href=\"ref-set-isdisjoint.html\" target=\"_blank\" rel=\"noopener noreferrer\">isdisjoint()</a></td><td>判断两个集合是否包含相同的元素，如果没有返回 True，否则返回 False。</td>\n",
    "  </tr>\n",
    "  <tr>\n",
    "    <td><a href=\"ref-set-issubset.html\" target=\"_blank\" rel=\"noopener noreferrer\">issubset()</a></td><td>判断指定集合是否为该方法参数集合的子集。</td>\n",
    "  </tr>\n",
    "<tr><td><a href=\"ref-set-issuperset.html\" target=\"_blank\" rel=\"noopener noreferrer\">issuperset()</a></td><td>判断该方法的参数集合是否为指定集合的子集</td></tr>\n",
    "<tr><td><a href=\"ref-set-pop.html\" target=\"_blank\" rel=\"noopener noreferrer\">pop()</a></td><td>随机移除元素</td></tr>\n",
    "<tr><td><a href=\"ref-set-remove.html\" target=\"_blank\" rel=\"noopener noreferrer\">remove()</a></td><td>移除指定元素</td></tr>\n",
    "  <tr>\n",
    "    <td><a href=\"ref-set-symmetric_difference.html\" target=\"_blank\" rel=\"noopener noreferrer\">symmetric_difference()</a></td><td>返回两个集合中不重复的元素集合。</td>\n",
    "  </tr>\n",
    "<tr><td><a href=\"ref-set-symmetric_difference_update.html\" target=\"_blank\" rel=\"noopener noreferrer\">symmetric_difference_update()</a></td><td>\n",
    "  移除当前集合中在另外一个指定集合相同的元素，并将另外一个指定集合中不同的元素插入到当前集合中。 </td></tr>\n",
    "  <tr>\n",
    "    <td><a href=\"ref-set-union.html\" target=\"_blank\" rel=\"noopener noreferrer\">union()</a></td><td>返回两个集合的并集</td>\n",
    "  </tr>\n",
    "<tr><td><a href=\"ref-set-update.html\" target=\"_blank\" rel=\"noopener noreferrer\">update()</a></td><td>给集合添加元素</td></tr>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Facebook'}\n",
      "{'Facebook', 'o', 'k', 'c', 'e', 'a', 'F', 'b'}\n",
      "{'Facebook', 'o', 'k', 'c', 'e', 'a', 'F', 'b'}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'Facebook'"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 增加\n",
    "basket.add(\"Facebook\")\n",
    "print(basket)\n",
    "# 添加\n",
    "basket.update(\"Facebook\")\n",
    "print(basket)\n",
    "# 删除\n",
    "#basket.remove(\"apple\")\n",
    "print(basket)\n",
    "#basket.remove('none')  # throw error!!!\n",
    "basket.discard('none') # don't throw error!!!\n",
    "basket.pop()# throw one element random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'k', 'c', 'e', 'a', 'F', 'b'}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算集合长度\n",
    "basket.pop()\n",
    "print(basket)\n",
    "len(basket)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "#清理集合\n",
    "basket.clear()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a id=Section4></a>\n",
    "## 3.4 映射类型\n",
    "字典是另一种可变容器模型，且可存储任意类型对象。\n",
    "字典的每个键值 key=>value 对用冒号 : 分割，每个对之间用逗号(,)分割，整个字典包括在花括号 {} 中 ,格式如下所示：\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 7.0.1 (20221109.1506)\n",
       " -->\n",
       "<!-- Title: 顺序结构 Pages: 1 -->\n",
       "<svg width=\"234pt\" height=\"188pt\"\n",
       " viewBox=\"0.00 0.00 234.00 188.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 184)\">\n",
       "<title>顺序结构</title>\n",
       "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-184 230,-184 230,4 -4,4\"/>\n",
       "<!-- 1 -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>1</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"145,-180 91,-180 91,-144 145,-144 145,-180\"/>\n",
       "<text text-anchor=\"middle\" x=\"118\" y=\"-158.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">字典</text>\n",
       "</g>\n",
       "<!-- 2 -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>2</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"70,-108 0,-108 0,-72 70,-72 70,-108\"/>\n",
       "<text text-anchor=\"middle\" x=\"35\" y=\"-86.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">name1：</text>\n",
       "</g>\n",
       "<!-- 1&#45;&gt;2 -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>1&#45;&gt;2</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M97.48,-143.7C87.41,-135.2 75.09,-124.81 64.07,-115.51\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"66.63,-113.09 56.73,-109.32 62.11,-118.45 66.63,-113.09\"/>\n",
       "</g>\n",
       "<!-- 3 -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>3</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"148,-108 88,-108 88,-72 148,-72 148,-108\"/>\n",
       "<text text-anchor=\"middle\" x=\"118\" y=\"-86.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">key2：</text>\n",
       "</g>\n",
       "<!-- 1&#45;&gt;3 -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>1&#45;&gt;3</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M118,-143.7C118,-136.41 118,-127.73 118,-119.54\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"121.5,-119.62 118,-109.62 114.5,-119.62 121.5,-119.62\"/>\n",
       "</g>\n",
       "<!-- 4 -->\n",
       "<g id=\"node4\" class=\"node\">\n",
       "<title>4</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"226,-108 166,-108 166,-72 226,-72 226,-108\"/>\n",
       "<text text-anchor=\"middle\" x=\"196\" y=\"-86.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">key3：</text>\n",
       "</g>\n",
       "<!-- 1&#45;&gt;4 -->\n",
       "<g id=\"edge3\" class=\"edge\">\n",
       "<title>1&#45;&gt;4</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M137.28,-143.7C146.66,-135.28 158.09,-125.02 168.38,-115.79\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"170.44,-118.64 175.54,-109.36 165.76,-113.43 170.44,-118.64\"/>\n",
       "</g>\n",
       "<!-- 5 -->\n",
       "<g id=\"node5\" class=\"node\">\n",
       "<title>5</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"62.5,-36 7.5,-36 7.5,0 62.5,0 62.5,-36\"/>\n",
       "<text text-anchor=\"middle\" x=\"35\" y=\"-14.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">Value1</text>\n",
       "</g>\n",
       "<!-- 2&#45;&gt;5 -->\n",
       "<g id=\"edge4\" class=\"edge\">\n",
       "<title>2&#45;&gt;5</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M35,-71.7C35,-64.41 35,-55.73 35,-47.54\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"38.5,-47.62 35,-37.62 31.5,-47.62 38.5,-47.62\"/>\n",
       "</g>\n",
       "<!-- 6 -->\n",
       "<g id=\"node6\" class=\"node\">\n",
       "<title>6</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"145.5,-36 90.5,-36 90.5,0 145.5,0 145.5,-36\"/>\n",
       "<text text-anchor=\"middle\" x=\"118\" y=\"-14.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">Value2</text>\n",
       "</g>\n",
       "<!-- 3&#45;&gt;6 -->\n",
       "<g id=\"edge5\" class=\"edge\">\n",
       "<title>3&#45;&gt;6</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M118,-71.7C118,-64.41 118,-55.73 118,-47.54\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"121.5,-47.62 118,-37.62 114.5,-47.62 121.5,-47.62\"/>\n",
       "</g>\n",
       "<!-- 7 -->\n",
       "<g id=\"node7\" class=\"node\">\n",
       "<title>7</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"223.5,-36 168.5,-36 168.5,0 223.5,0 223.5,-36\"/>\n",
       "<text text-anchor=\"middle\" x=\"196\" y=\"-14.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">Value3</text>\n",
       "</g>\n",
       "<!-- 4&#45;&gt;7 -->\n",
       "<g id=\"edge6\" class=\"edge\">\n",
       "<title>4&#45;&gt;7</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M196,-71.7C196,-64.41 196,-55.73 196,-47.54\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"199.5,-47.62 196,-37.62 192.5,-47.62 199.5,-47.62\"/>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<graphviz.graphs.Digraph at 0x1bcf0a8e200>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "import graphviz\n",
    "dot=graphviz.Digraph(comment='the round table',name=\"顺序结构\",node_attr={'shape': 'box'})\n",
    "dot.node('1','字典')\n",
    "dot.node('2','name1：')\n",
    "dot.node('3','key2：')\n",
    "dot.node('4','key3：')\n",
    "dot.node('5','Value1')\n",
    "dot.node('6','Value2')\n",
    "dot.node('7','Value3')\n",
    "dot.edges(['12','13','14','25','36','47'])\n",
    "dot"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 基本操作\n",
    "键必须是唯一的，但值则不必。\n",
    "\n",
    "值可以取任何数据类型，但键必须是不可变的，如字符串，数字。\n",
    "\n",
    "一个简单的字典实例："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'zhangsan', 'Age': 20, 'url': 'www.xauat.edu.cn'}\n"
     ]
    }
   ],
   "source": [
    "dict = {'name': 'zhangsan', 'Age': 20, 'url': 'www.xauat.edu.cn'}\n",
    "print(dict)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 访问字典里的值  \n",
    "把相应的键放入到方括号中，如下实例:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'zhangsan'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict['name']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 修改字典   \n",
    "向字典添加新内容的方法是增加新的键/值对，修改或删除已有键/值对如下实例:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': '李四', 'Age': 20, 'url': 'www.xauat.edu.cn', 'sex': '男'}\n"
     ]
    }
   ],
   "source": [
    "dict['name']=\"李四\"\n",
    "dict['sex']='男'\n",
    "print(dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['c:\\\\ProgramData\\\\miniconda3\\\\Lib\\\\site-packages\\\\win32\\\\lib',\n",
       " 'c:\\\\ProgramData\\\\miniconda3\\\\Lib\\\\site-packages\\\\Pythonwin',\n",
       " 'c:\\\\ProgramData\\\\miniconda3\\\\Lib\\\\site-packages\\\\win32',\n",
       " 'c:\\\\ProgramData\\\\miniconda3\\\\Lib\\\\site-packages',\n",
       " 'c:\\\\ProgramData\\\\miniconda3\\\\python312.zip',\n",
       " 'c:\\\\ProgramData\\\\miniconda3\\\\DLLs',\n",
       " 'c:\\\\ProgramData\\\\miniconda3\\\\Lib',\n",
       " 'c:\\\\ProgramData\\\\miniconda3',\n",
       " '']"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sys\n",
    "mypath=sys.path\n",
    "def myFunc(e):\n",
    "  return len(e)\n",
    "\n",
    "mypath.sort(reverse=True, key=myFunc)\n",
    "len(mypath)\n",
    "mypath"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Defaulting to user installation because normal site-packages is not writeable\n",
      "Collecting nbformat\n",
      "  Downloading nbformat-5.10.4-py3-none-any.whl.metadata (3.6 kB)\n",
      "Collecting fastjsonschema>=2.15 (from nbformat)\n",
      "  Downloading fastjsonschema-2.21.1-py3-none-any.whl.metadata (2.2 kB)\n",
      "Collecting jsonschema>=2.6 (from nbformat)\n",
      "  Downloading jsonschema-4.23.0-py3-none-any.whl.metadata (7.9 kB)\n",
      "Requirement already satisfied: jupyter-core!=5.0.*,>=4.12 in c:\\programdata\\miniconda3\\lib\\site-packages (from nbformat) (5.7.2)\n",
      "Requirement already satisfied: traitlets>=5.1 in c:\\programdata\\miniconda3\\lib\\site-packages (from nbformat) (5.14.3)\n",
      "Collecting attrs>=22.2.0 (from jsonschema>=2.6->nbformat)\n",
      "  Downloading attrs-24.2.0-py3-none-any.whl.metadata (11 kB)\n",
      "Collecting jsonschema-specifications>=2023.03.6 (from jsonschema>=2.6->nbformat)\n",
      "  Downloading jsonschema_specifications-2024.10.1-py3-none-any.whl.metadata (3.0 kB)\n",
      "Collecting referencing>=0.28.4 (from jsonschema>=2.6->nbformat)\n",
      "  Downloading referencing-0.35.1-py3-none-any.whl.metadata (2.8 kB)\n",
      "Collecting rpds-py>=0.7.1 (from jsonschema>=2.6->nbformat)\n",
      "  Downloading rpds_py-0.22.1-cp312-cp312-win_amd64.whl.metadata (4.2 kB)\n",
      "Requirement already satisfied: platformdirs>=2.5 in c:\\programdata\\miniconda3\\lib\\site-packages (from jupyter-core!=5.0.*,>=4.12->nbformat) (3.10.0)\n",
      "Requirement already satisfied: pywin32>=300 in c:\\programdata\\miniconda3\\lib\\site-packages (from jupyter-core!=5.0.*,>=4.12->nbformat) (307)\n",
      "Downloading nbformat-5.10.4-py3-none-any.whl (78 kB)\n",
      "Downloading fastjsonschema-2.21.1-py3-none-any.whl (23 kB)\n",
      "Downloading jsonschema-4.23.0-py3-none-any.whl (88 kB)\n",
      "Downloading attrs-24.2.0-py3-none-any.whl (63 kB)\n",
      "Downloading jsonschema_specifications-2024.10.1-py3-none-any.whl (18 kB)\n",
      "Downloading referencing-0.35.1-py3-none-any.whl (26 kB)\n",
      "Downloading rpds_py-0.22.1-cp312-cp312-win_amd64.whl (235 kB)\n",
      "Installing collected packages: fastjsonschema, rpds-py, attrs, referencing, jsonschema-specifications, jsonschema, nbformat\n",
      "Successfully installed attrs-24.2.0 fastjsonschema-2.21.1 jsonschema-4.23.0 jsonschema-specifications-2024.10.1 nbformat-5.10.4 referencing-0.35.1 rpds-py-0.22.1\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "  WARNING: The script jsonschema.exe is installed in 'C:\\Users\\H3C\\AppData\\Roaming\\Python\\Python312\\Scripts' which is not on PATH.\n",
      "  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.\n",
      "  WARNING: The script jupyter-trust.exe is installed in 'C:\\Users\\H3C\\AppData\\Roaming\\Python\\Python312\\Scripts' which is not on PATH.\n",
      "  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.\n"
     ]
    }
   ],
   "source": [
    "%pip install nbformat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'cells': [{'cell_type': 'markdown', 'metadata': {}, 'source': '<img src=\".\\\\\\\\diyLogo.png\" alt=\"some_text\">\\n<h1> 第三讲 程序设计基础</h1>\\n<a id=backup></a>\\n<H2>目录</H2>  \\n\\n[3.1 组合数据类型概述](#Section1)  \\n[3.2 序列类型](#Section2)  \\n[3.3 集合类型](#Section3)     \\n[3.4 映射类型](#Section4)  '}, {'cell_type': 'markdown', 'metadata': {}, 'source': '<a id = Section1> </a>\\n## 3.1 组合数据类型概述\\n'}, {'cell_type': 'markdown', 'metadata': {}, 'source': '<a id = Section2> </a>\\n## 3.2 序列类型\\n### 字符串\\n### 元组\\n### 列表\\n\\n<p><a href=\"https://yanghailin.blog.csdn.net/article/details/81126087?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-5.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-5.no_search_link\">\\nthis is example of python</a></p'}, {'cell_type': 'markdown', 'metadata': {}, 'source': '### 3.2.1字符串运算\\n\\n'}, {'cell_type': 'code', 'execution_count': 1, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': 'a + b 输出结果： HelloPython\\na * 2 输出结果： HelloHello\\na[1] 输出结果： e\\na[1:4] 输出结果： ell\\nH 在变量 a 中\\nM 不在变量 a 中\\n\\\\n\\n\\\\n\\n'}], 'source': 'a = \"Hello\"\\nb = \"Python\"\\n \\nprint(\"a + b 输出结果：\", a + b)\\nprint(\"a * 2 输出结果：\", a * 2)\\nprint(\"a[1] 输出结果：\", a[1])\\nprint(\"a[1:4] 输出结果：\", a[1:4])\\n# in \\nif( \"H\" in a) :\\n    print(\"H 在变量 a 中\")\\nelse :\\n    print(\"H 不在变量 a 中\")\\n#not in \\nif( \"M\" not in a) :\\n    print(\"M 不在变量 a 中\")\\nelse :\\n    print(\"M 在变量 a 中\")\\n# r R 直接打印字符串 \\nprint (r\\'\\\\n\\')\\nprint (R\\'\\\\n\\')'}, {'cell_type': 'markdown', 'metadata': {}, 'source': '### 3.2.2元组\\nPython 的元组与列表类似，不同之处在于元组的元素不能修改,可以合并。\\n\\n元组使用小括号 ( )，列表使用方括号 [ ]。\\n\\n元组创建很简单，只需要在括号中添加元素，并使用逗号隔开即可。'}, {'cell_type': 'code', 'execution_count': 3, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"('Google', 'Runoob', 1997, 2000) \\n tup2 \\n ('a', 'b', 'c', 'd') \\n <class 'tuple'>\\n\"}, {'data': {'text/plain': \"'Google'\"}, 'execution_count': 3, 'metadata': {}, 'output_type': 'execute_result'}], 'source': 'tup1 = (\\'Google\\', \\'Runoob\\', 1997, 2000)\\ntup2 = (1, 2, 3, 4, 5 )\\ntup3 = \"a\", \"b\", \"c\", \"d\"   #  不需要括号也可以\\ntype(tup3)\\nprint(tup1,\"\\\\n\",\"tup2\",\"\\\\n\",tup3,\"\\\\n\",type(tup3))\\ntup1[0]'}, {'cell_type': 'code', 'execution_count': 28, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': '2448321434544\\n2448321266176\\n'}], 'source': 'print(id(tup1))\\ntup1=1,2,3\\nprint(id(tup1))\\n'}, {'cell_type': 'markdown', 'metadata': {}, 'source': '### 3.2.3列表\\n序列是 Python 中最基本的数据结构。\\n\\n序列中的每个值都有对应的位置值，称之为索引，第一个索引是 0，第二个索引是 1，依此类推。\\n\\nPython 有 6 个序列的内置类型，但最常见的是列表和元组。\\n\\n列表都可以进行的操作包括索引，切片，加，乘，检查成员。\\n\\n此外，Python 已经内置确定序列的长度以及确定最大和最小的元素的方法。\\n\\n列表是最常用的 Python 数据类型，它可以作为一个方括号内的逗号分隔值出现。\\n\\n列表的数据项不需要具有相同的类型\\n\\n创建一个列表，只要把逗号分隔的不同的数据项使用方括号括起来即可。如下所示：'}, {'cell_type': 'code', 'execution_count': 1, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': 'red\\nwhite\\nblack\\n'}], 'source': \"list1 = ['red', 'green', 'blue', 'yellow', 'white', 'black']\\nprint( list1[0] )\\nprint( list1[-2] )\\nprint( list1[-1] )\\nlist1[0]='lightred'\"}, {'cell_type': 'code', 'execution_count': 13, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"list[0]:  Google\\nlist[0:4]:  ['Google', 'Runoob', 'Zhihu', 'Taobao', 'Wiki']\\n\"}], 'source': 'list = [\\'Google\\', \\'Runoob\\', \"Zhihu\", \"Taobao\", \"Wiki\"]\\n \\n# 读取第二位\\nprint (\"list[0]: \", list[0])\\n# 从第二位开始（包含）截取到倒数第二位（不包含）\\nprint (\"list[0:4]: \", list[0:5])'}, {'cell_type': 'code', 'execution_count': 16, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"更新后的第三个元素为 :  ['x', 'a', 2001, 'a', 't']\\n更新后的列表 :  ['x', 'a', 2001, 'a', 't', 'Baidu']\\n\"}], 'source': '#\\nlist[2] = 2001\\nprint (\"更新后的第三个元素为 : \", list)\\n \\nlist.append(\\'Baidu\\')\\nprint (\"更新后的列表 : \", list)\\n\\nlist[:]=\\'\\''}, {'cell_type': 'code', 'execution_count': 17, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': '[]\\n'}], 'source': 'print(list)'}, {'cell_type': 'code', 'execution_count': None, 'metadata': {}, 'outputs': [], 'source': '#删除元素\\ndel list[2]\\nprint (\"删除第三个元素 : \", list)'}, {'cell_type': 'markdown', 'metadata': {}, 'source': '### Python列表函数&方法\\nPython包含以下函数:\\n<table><tr>\\n<th style=\"width:5%\">序号</th><th style=\"width:95%\">函数</th></tr>\\n\\n<tr><td>1</td><td><a href=\"python3-att-list-len.html\">len(list)</a><br>列表元素个数</td></tr>\\n<tr><td>2</td><td><a href=\"python3-att-list-max.html\">max(list)</a><br>返回列表元素最大值</td></tr>\\n<tr><td>3</td><td><a href=\"python3-att-list-min.html\">min(list)</a><br>返回列表元素最小值</td></tr>\\n<tr><td>4</td><td><a href=\"python3-att-list-list.html\">list(seq)</a><br>将元组转换为列表</td></tr>\\n</table>\\n\\nPython包含以下方法:\\n<table><tr>\\n<th style=\"width:5%\">序号</th><th style=\"width:95%\">方法</th></tr>\\n<tr><td>1</td><td><a href=\"python3-att-list-append.html\">list.append(obj)</a><br>在列表末尾添加新的对象</td></tr>\\n<tr><td>2</td><td><a href=\"python3-att-list-count.html\">list.count(obj)</a><br>统计某个元素在列表中出现的次数</td></tr>\\n<tr><td>3</td><td><a href=\"python3-att-list-extend.html\">list.extend(seq)</a><br>在列表末尾一次性追加另一个序列中的多个值（用新列表扩展原来的列表）</td></tr>\\n<tr><td>4</td><td><a href=\"python3-att-list-index.html\">list.index(obj)</a><br>从列表中找出某个值第一个匹配项的索引位置</td></tr>\\n<tr><td>5</td><td><a href=\"python3-att-list-insert.html\">list.insert(index, obj)</a><br>将对象插入列表</td></tr>\\n<tr><td>6</td><td><a href=\"python3-att-list-pop.html\">list.pop([index=-1])</a><br>移除列表中的一个元素（默认最后一个元素），并且返回该元素的值</td></tr>\\n<tr><td>7</td><td><a href=\"python3-att-list-remove.html\">list.remove(obj)</a><br>移除列表中某个值的第一个匹配项</td></tr>\\n<tr><td>8</td><td><a href=\"python3-att-list-reverse.html\">list.reverse()</a><br>反向列表中元素</td></tr>\\n<tr><td>9</td><td><a href=\"python3-att-list-sort.html\">\\tlist.sort( key=None, reverse=False)</a><br>对原列表进行排序</td></tr>\\n<tr><td>10</td><td><a href=\"python3-att-list-clear.html\">list.clear()</a><br>清空列表</td></tr>\\n<tr><td>11</td><td><a href=\"python3-att-list-copy.html\">list.copy()</a><br>复制列表</td></tr>\\n</table>\\n'}, {'cell_type': 'code', 'execution_count': 27, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"['Mitsubishi', 'Ford', 'BMW', 'VW']\\n\"}], 'source': \"# A function that returns the length of the value:\\ndef myFunc(e):\\n  return len(e)\\ncars = ['Ford', 'Mitsubishi', 'BMW', 'VW']\\ncars.sort(reverse=True, key=myFunc)\\nprint(cars)\"}, {'cell_type': 'code', 'execution_count': 28, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"['Mitsubishi', 'Ford', 'BMW']\\n\"}], 'source': 'cars.pop()\\nprint(cars)\\n'}, {'cell_type': 'markdown', 'metadata': {}, 'source': '<a id=Section3></a>\\n## 3.3 集合类型\\n集合（set）是一个无序的不重复元素序列。\\n\\n可以使用大括号 { } 或者 set() 函数创建集合，注意：创建一个空集合必须用 set() 而不是 { }，因为 { } 是用来创建一个空字典。'}, {'cell_type': 'markdown', 'metadata': {}, 'source': '### 3.3.1基本操作：'}, {'cell_type': 'code', 'execution_count': None, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': '4\\n'}, {'ename': 'TypeError', 'evalue': \"'set' object is not subscriptable\", 'output_type': 'error', 'traceback': ['\\x1b[1;31m---------------------------------------------------------------------------\\x1b[0m', '\\x1b[1;31mTypeError\\x1b[0m                                 Traceback (most recent call last)', \"Cell \\x1b[1;32mIn[4], line 3\\x1b[0m\\n\\x1b[0;32m      1\\x1b[0m basket \\x1b[38;5;241m=\\x1b[39m {\\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124mapple\\x1b[39m\\x1b[38;5;124m'\\x1b[39m, \\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124morange\\x1b[39m\\x1b[38;5;124m'\\x1b[39m, \\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124mapple\\x1b[39m\\x1b[38;5;124m'\\x1b[39m, \\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124mpear\\x1b[39m\\x1b[38;5;124m'\\x1b[39m, \\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124morange\\x1b[39m\\x1b[38;5;124m'\\x1b[39m, \\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124mbanana\\x1b[39m\\x1b[38;5;124m'\\x1b[39m}\\n\\x1b[0;32m      2\\x1b[0m \\x1b[38;5;28mprint\\x1b[39m(\\x1b[38;5;28mlen\\x1b[39m(basket))                      \\x1b[38;5;66;03m# 这里演示的是去重功能\\x1b[39;00m\\n\\x1b[1;32m----> 3\\x1b[0m \\x1b[43mbasket\\x1b[49m\\x1b[43m[\\x1b[49m\\x1b[38;5;241;43m0\\x1b[39;49m\\x1b[43m]\\x1b[49m\\n\", \"\\x1b[1;31mTypeError\\x1b[0m: 'set' object is not subscriptable\"]}], 'source': \"basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}\\nprint(len(basket))                      # 这里演示的是去重功能\\nbasket[0] #不能索引\"}, {'cell_type': 'code', 'execution_count': 2, 'metadata': {}, 'outputs': [{'data': {'text/plain': 'True'}, 'execution_count': 2, 'metadata': {}, 'output_type': 'execute_result'}], 'source': \"{'orange', 'banana', 'pear', 'apple'}\\n'orange' in basket                 # 快速判断元素是否在集合内\"}, {'cell_type': 'code', 'execution_count': 3, 'metadata': {}, 'outputs': [{'data': {'text/plain': 'False'}, 'execution_count': 3, 'metadata': {}, 'output_type': 'execute_result'}], 'source': \"'crabgrass' in basket\"}, {'cell_type': 'code', 'execution_count': 32, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"a= {'d', 'c', 'r', 'a', 'b'}\\nb= {'z', 'm', 'c', 'l', 'a'}\\n\"}, {'data': {'text/plain': \"{'b', 'd', 'r'}\"}, 'execution_count': 32, 'metadata': {}, 'output_type': 'execute_result'}], 'source': \"# 下面展示两个集合间的运算.\\na = set('abracadabra')\\nb = set('alacazam')\\nprint('a=',a)\\nprint('b=',b)\\n# 集合a中包含而集合b中不包含的元素                                 \\na - b                              \"}, {'cell_type': 'code', 'execution_count': 7, 'metadata': {}, 'outputs': [{'data': {'text/plain': \"{'a', 'b', 'c', 'd', 'l', 'm', 'r', 'z'}\"}, 'execution_count': 7, 'metadata': {}, 'output_type': 'execute_result'}], 'source': '# 集合a或b中包含的所有元素（并集）\\na | b                              '}, {'cell_type': 'code', 'execution_count': 8, 'metadata': {}, 'outputs': [{'data': {'text/plain': \"{'a', 'c'}\"}, 'execution_count': 8, 'metadata': {}, 'output_type': 'execute_result'}], 'source': '# 集合a和b中都包含了的元素(交集)\\na & b                              '}, {'cell_type': 'code', 'execution_count': 9, 'metadata': {}, 'outputs': [{'data': {'text/plain': \"{'b', 'd', 'l', 'm', 'r', 'z'}\"}, 'execution_count': 9, 'metadata': {}, 'output_type': 'execute_result'}], 'source': '# 不同时包含于a和b的元素（交集的补集）\\na ^ b                              '}, {'cell_type': 'code', 'execution_count': 5, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"{'d', 'r'}\\n\"}], 'source': \"#类似列表推导式，同样集合支持集合推导式(Set comprehension):\\na = {x  for x in 'abracadabra' \\n              if x not in 'abc'}\\nprint(a)\"}, {'cell_type': 'markdown', 'metadata': {}, 'source': '### 3.3.2集合运算\\n\\n<table><tr>\\n<th>方法</th>\\n<th>描述</th>\\n</tr>\\n<tr><td><a href=\"ref-set-add.html\" target=\"_blank\" rel=\"noopener noreferrer\">add()</a></td><td>为集合添加元素</td></tr>\\n<tr><td><a href=\"ref-set-clear.html\" target=\"_blank\" rel=\"noopener noreferrer\">clear()</a></td><td>移除集合中的所有元素</td></tr>\\n<tr><td><a href=\"ref-set-copy.html\" target=\"_blank\" rel=\"noopener noreferrer\">copy()</a></td><td>拷贝一个集合</td></tr>\\n  <tr>\\n    <td><a href=\"ref-set-difference.html\" target=\"_blank\" rel=\"noopener noreferrer\">difference()</a></td><td>返回多个集合的差集</td>\\n  </tr>\\n  <tr>\\n    <td><a href=\"ref-set-difference_update.html\" target=\"_blank\" rel=\"noopener noreferrer\">difference_update()</a></td><td>移除集合中的元素，该元素在指定的集合也存在。</td>\\n  </tr>\\n<tr><td><a href=\"ref-set-discard.html\" target=\"_blank\" rel=\"noopener noreferrer\">discard()</a></td><td>删除集合中指定的元素</td></tr>\\n  <tr>\\n    <td><a href=\"ref-set-intersection.html\" target=\"_blank\" rel=\"noopener noreferrer\">intersection()</a></td><td>返回集合的交集</td>\\n  </tr>\\n<tr><td><a href=\"ref-set-intersection_update.html\" target=\"_blank\" rel=\"noopener noreferrer\">intersection_update()</a></td><td>\\n  返回集合的交集。</td></tr>\\n  <tr>\\n    <td><a href=\"ref-set-isdisjoint.html\" target=\"_blank\" rel=\"noopener noreferrer\">isdisjoint()</a></td><td>判断两个集合是否包含相同的元素，如果没有返回 True，否则返回 False。</td>\\n  </tr>\\n  <tr>\\n    <td><a href=\"ref-set-issubset.html\" target=\"_blank\" rel=\"noopener noreferrer\">issubset()</a></td><td>判断指定集合是否为该方法参数集合的子集。</td>\\n  </tr>\\n<tr><td><a href=\"ref-set-issuperset.html\" target=\"_blank\" rel=\"noopener noreferrer\">issuperset()</a></td><td>判断该方法的参数集合是否为指定集合的子集</td></tr>\\n<tr><td><a href=\"ref-set-pop.html\" target=\"_blank\" rel=\"noopener noreferrer\">pop()</a></td><td>随机移除元素</td></tr>\\n<tr><td><a href=\"ref-set-remove.html\" target=\"_blank\" rel=\"noopener noreferrer\">remove()</a></td><td>移除指定元素</td></tr>\\n  <tr>\\n    <td><a href=\"ref-set-symmetric_difference.html\" target=\"_blank\" rel=\"noopener noreferrer\">symmetric_difference()</a></td><td>返回两个集合中不重复的元素集合。</td>\\n  </tr>\\n<tr><td><a href=\"ref-set-symmetric_difference_update.html\" target=\"_blank\" rel=\"noopener noreferrer\">symmetric_difference_update()</a></td><td>\\n  移除当前集合中在另外一个指定集合相同的元素，并将另外一个指定集合中不同的元素插入到当前集合中。 </td></tr>\\n  <tr>\\n    <td><a href=\"ref-set-union.html\" target=\"_blank\" rel=\"noopener noreferrer\">union()</a></td><td>返回两个集合的并集</td>\\n  </tr>\\n<tr><td><a href=\"ref-set-update.html\" target=\"_blank\" rel=\"noopener noreferrer\">update()</a></td><td>给集合添加元素</td></tr>\\n</table>'}, {'cell_type': 'code', 'execution_count': 52, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"{'Facebook'}\\n{'Facebook', 'o', 'k', 'c', 'e', 'a', 'F', 'b'}\\n{'Facebook', 'o', 'k', 'c', 'e', 'a', 'F', 'b'}\\n\"}, {'data': {'text/plain': \"'Facebook'\"}, 'execution_count': 52, 'metadata': {}, 'output_type': 'execute_result'}], 'source': '# 增加\\nbasket.add(\"Facebook\")\\nprint(basket)\\n# 添加\\nbasket.update(\"Facebook\")\\nprint(basket)\\n# 删除\\n#basket.remove(\"apple\")\\nprint(basket)\\n#basket.remove(\\'none\\')  # throw error!!!\\nbasket.discard(\\'none\\') # don\\'t throw error!!!\\nbasket.pop()# throw one element random'}, {'cell_type': 'code', 'execution_count': 53, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"{'k', 'c', 'e', 'a', 'F', 'b'}\\n\"}, {'data': {'text/plain': '6'}, 'execution_count': 53, 'metadata': {}, 'output_type': 'execute_result'}], 'source': '# 计算集合长度\\nbasket.pop()\\nprint(basket)\\nlen(basket)'}, {'cell_type': 'code', 'execution_count': 22, 'metadata': {}, 'outputs': [], 'source': '#清理集合\\nbasket.clear()\\n'}, {'cell_type': 'markdown', 'metadata': {}, 'source': '<a id=Section4></a>\\n## 3.4 映射类型\\n字典是另一种可变容器模型，且可存储任意类型对象。\\n字典的每个键值 key=>value 对用冒号 : 分割，每个对之间用逗号(,)分割，整个字典包括在花括号 {} 中 ,格式如下所示：\\n'}, {'cell_type': 'code', 'execution_count': 1, 'metadata': {}, 'outputs': [{'data': {'image/svg+xml': '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\\n<!-- Generated by graphviz version 7.0.1 (20221109.1506)\\n -->\\n<!-- Title: 顺序结构 Pages: 1 -->\\n<svg width=\"234pt\" height=\"188pt\"\\n viewBox=\"0.00 0.00 234.00 188.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 184)\">\\n<title>顺序结构</title>\\n<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-184 230,-184 230,4 -4,4\"/>\\n<!-- 1 -->\\n<g id=\"node1\" class=\"node\">\\n<title>1</title>\\n<polygon fill=\"none\" stroke=\"black\" points=\"145,-180 91,-180 91,-144 145,-144 145,-180\"/>\\n<text text-anchor=\"middle\" x=\"118\" y=\"-158.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">字典</text>\\n</g>\\n<!-- 2 -->\\n<g id=\"node2\" class=\"node\">\\n<title>2</title>\\n<polygon fill=\"none\" stroke=\"black\" points=\"70,-108 0,-108 0,-72 70,-72 70,-108\"/>\\n<text text-anchor=\"middle\" x=\"35\" y=\"-86.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">name1：</text>\\n</g>\\n<!-- 1&#45;&gt;2 -->\\n<g id=\"edge1\" class=\"edge\">\\n<title>1&#45;&gt;2</title>\\n<path fill=\"none\" stroke=\"black\" d=\"M97.48,-143.7C87.41,-135.2 75.09,-124.81 64.07,-115.51\"/>\\n<polygon fill=\"black\" stroke=\"black\" points=\"66.63,-113.09 56.73,-109.32 62.11,-118.45 66.63,-113.09\"/>\\n</g>\\n<!-- 3 -->\\n<g id=\"node3\" class=\"node\">\\n<title>3</title>\\n<polygon fill=\"none\" stroke=\"black\" points=\"148,-108 88,-108 88,-72 148,-72 148,-108\"/>\\n<text text-anchor=\"middle\" x=\"118\" y=\"-86.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">key2：</text>\\n</g>\\n<!-- 1&#45;&gt;3 -->\\n<g id=\"edge2\" class=\"edge\">\\n<title>1&#45;&gt;3</title>\\n<path fill=\"none\" stroke=\"black\" d=\"M118,-143.7C118,-136.41 118,-127.73 118,-119.54\"/>\\n<polygon fill=\"black\" stroke=\"black\" points=\"121.5,-119.62 118,-109.62 114.5,-119.62 121.5,-119.62\"/>\\n</g>\\n<!-- 4 -->\\n<g id=\"node4\" class=\"node\">\\n<title>4</title>\\n<polygon fill=\"none\" stroke=\"black\" points=\"226,-108 166,-108 166,-72 226,-72 226,-108\"/>\\n<text text-anchor=\"middle\" x=\"196\" y=\"-86.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">key3：</text>\\n</g>\\n<!-- 1&#45;&gt;4 -->\\n<g id=\"edge3\" class=\"edge\">\\n<title>1&#45;&gt;4</title>\\n<path fill=\"none\" stroke=\"black\" d=\"M137.28,-143.7C146.66,-135.28 158.09,-125.02 168.38,-115.79\"/>\\n<polygon fill=\"black\" stroke=\"black\" points=\"170.44,-118.64 175.54,-109.36 165.76,-113.43 170.44,-118.64\"/>\\n</g>\\n<!-- 5 -->\\n<g id=\"node5\" class=\"node\">\\n<title>5</title>\\n<polygon fill=\"none\" stroke=\"black\" points=\"62.5,-36 7.5,-36 7.5,0 62.5,0 62.5,-36\"/>\\n<text text-anchor=\"middle\" x=\"35\" y=\"-14.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">Value1</text>\\n</g>\\n<!-- 2&#45;&gt;5 -->\\n<g id=\"edge4\" class=\"edge\">\\n<title>2&#45;&gt;5</title>\\n<path fill=\"none\" stroke=\"black\" d=\"M35,-71.7C35,-64.41 35,-55.73 35,-47.54\"/>\\n<polygon fill=\"black\" stroke=\"black\" points=\"38.5,-47.62 35,-37.62 31.5,-47.62 38.5,-47.62\"/>\\n</g>\\n<!-- 6 -->\\n<g id=\"node6\" class=\"node\">\\n<title>6</title>\\n<polygon fill=\"none\" stroke=\"black\" points=\"145.5,-36 90.5,-36 90.5,0 145.5,0 145.5,-36\"/>\\n<text text-anchor=\"middle\" x=\"118\" y=\"-14.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">Value2</text>\\n</g>\\n<!-- 3&#45;&gt;6 -->\\n<g id=\"edge5\" class=\"edge\">\\n<title>3&#45;&gt;6</title>\\n<path fill=\"none\" stroke=\"black\" d=\"M118,-71.7C118,-64.41 118,-55.73 118,-47.54\"/>\\n<polygon fill=\"black\" stroke=\"black\" points=\"121.5,-47.62 118,-37.62 114.5,-47.62 121.5,-47.62\"/>\\n</g>\\n<!-- 7 -->\\n<g id=\"node7\" class=\"node\">\\n<title>7</title>\\n<polygon fill=\"none\" stroke=\"black\" points=\"223.5,-36 168.5,-36 168.5,0 223.5,0 223.5,-36\"/>\\n<text text-anchor=\"middle\" x=\"196\" y=\"-14.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">Value3</text>\\n</g>\\n<!-- 4&#45;&gt;7 -->\\n<g id=\"edge6\" class=\"edge\">\\n<title>4&#45;&gt;7</title>\\n<path fill=\"none\" stroke=\"black\" d=\"M196,-71.7C196,-64.41 196,-55.73 196,-47.54\"/>\\n<polygon fill=\"black\" stroke=\"black\" points=\"199.5,-47.62 196,-37.62 192.5,-47.62 199.5,-47.62\"/>\\n</g>\\n</g>\\n</svg>\\n', 'text/plain': '<graphviz.graphs.Digraph at 0x1bcf0a8e200>'}, 'execution_count': 1, 'metadata': {}, 'output_type': 'execute_result'}], 'source': '\\nimport graphviz\\ndot=graphviz.Digraph(comment=\\'the round table\\',name=\"顺序结构\",node_attr={\\'shape\\': \\'box\\'})\\ndot.node(\\'1\\',\\'字典\\')\\ndot.node(\\'2\\',\\'name1：\\')\\ndot.node(\\'3\\',\\'key2：\\')\\ndot.node(\\'4\\',\\'key3：\\')\\ndot.node(\\'5\\',\\'Value1\\')\\ndot.node(\\'6\\',\\'Value2\\')\\ndot.node(\\'7\\',\\'Value3\\')\\ndot.edges([\\'12\\',\\'13\\',\\'14\\',\\'25\\',\\'36\\',\\'47\\'])\\ndot'}, {'cell_type': 'markdown', 'metadata': {}, 'source': '### 基本操作\\n键必须是唯一的，但值则不必。\\n\\n值可以取任何数据类型，但键必须是不可变的，如字符串，数字。\\n\\n一个简单的字典实例：'}, {'cell_type': 'code', 'execution_count': 55, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"{'name': 'zhangsan', 'Age': 20, 'url': 'www.xauat.edu.cn'}\\n\"}], 'source': \"dict = {'name': 'zhangsan', 'Age': 20, 'url': 'www.xauat.edu.cn'}\\nprint(dict)\"}, {'cell_type': 'markdown', 'metadata': {}, 'source': '### 访问字典里的值  \\n把相应的键放入到方括号中，如下实例:'}, {'cell_type': 'code', 'execution_count': 4, 'metadata': {}, 'outputs': [{'data': {'text/plain': \"'zhangsan'\"}, 'execution_count': 4, 'metadata': {}, 'output_type': 'execute_result'}], 'source': \"dict['name']\"}, {'cell_type': 'markdown', 'metadata': {}, 'source': '### 修改字典   \\n向字典添加新内容的方法是增加新的键/值对，修改或删除已有键/值对如下实例:'}, {'cell_type': 'code', 'execution_count': 7, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"{'name': '李四', 'Age': 20, 'url': 'www.xauat.edu.cn', 'sex': '男'}\\n\"}], 'source': 'dict[\\'name\\']=\"李四\"\\ndict[\\'sex\\']=\\'男\\'\\nprint(dict)'}, {'cell_type': 'code', 'execution_count': 20, 'metadata': {}, 'outputs': [{'data': {'text/plain': \"['c:\\\\\\\\ProgramData\\\\\\\\miniconda3\\\\\\\\Lib\\\\\\\\site-packages\\\\\\\\win32\\\\\\\\lib',\\n 'c:\\\\\\\\ProgramData\\\\\\\\miniconda3\\\\\\\\Lib\\\\\\\\site-packages\\\\\\\\Pythonwin',\\n 'c:\\\\\\\\ProgramData\\\\\\\\miniconda3\\\\\\\\Lib\\\\\\\\site-packages\\\\\\\\win32',\\n 'c:\\\\\\\\ProgramData\\\\\\\\miniconda3\\\\\\\\Lib\\\\\\\\site-packages',\\n 'c:\\\\\\\\ProgramData\\\\\\\\miniconda3\\\\\\\\python312.zip',\\n 'c:\\\\\\\\ProgramData\\\\\\\\miniconda3\\\\\\\\DLLs',\\n 'c:\\\\\\\\ProgramData\\\\\\\\miniconda3\\\\\\\\Lib',\\n 'c:\\\\\\\\ProgramData\\\\\\\\miniconda3',\\n '']\"}, 'execution_count': 20, 'metadata': {}, 'output_type': 'execute_result'}], 'source': 'import sys\\nmypath=sys.path\\ndef myFunc(e):\\n  return len(e)\\n\\nmypath.sort(reverse=True, key=myFunc)\\nlen(mypath)\\nmypath'}, {'cell_type': 'code', 'execution_count': 25, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': 'Defaulting to user installation because normal site-packages is not writeable\\nCollecting nbformat\\n  Downloading nbformat-5.10.4-py3-none-any.whl.metadata (3.6 kB)\\nCollecting fastjsonschema>=2.15 (from nbformat)\\n  Downloading fastjsonschema-2.21.1-py3-none-any.whl.metadata (2.2 kB)\\nCollecting jsonschema>=2.6 (from nbformat)\\n  Downloading jsonschema-4.23.0-py3-none-any.whl.metadata (7.9 kB)\\nRequirement already satisfied: jupyter-core!=5.0.*,>=4.12 in c:\\\\programdata\\\\miniconda3\\\\lib\\\\site-packages (from nbformat) (5.7.2)\\nRequirement already satisfied: traitlets>=5.1 in c:\\\\programdata\\\\miniconda3\\\\lib\\\\site-packages (from nbformat) (5.14.3)\\nCollecting attrs>=22.2.0 (from jsonschema>=2.6->nbformat)\\n  Downloading attrs-24.2.0-py3-none-any.whl.metadata (11 kB)\\nCollecting jsonschema-specifications>=2023.03.6 (from jsonschema>=2.6->nbformat)\\n  Downloading jsonschema_specifications-2024.10.1-py3-none-any.whl.metadata (3.0 kB)\\nCollecting referencing>=0.28.4 (from jsonschema>=2.6->nbformat)\\n  Downloading referencing-0.35.1-py3-none-any.whl.metadata (2.8 kB)\\nCollecting rpds-py>=0.7.1 (from jsonschema>=2.6->nbformat)\\n  Downloading rpds_py-0.22.1-cp312-cp312-win_amd64.whl.metadata (4.2 kB)\\nRequirement already satisfied: platformdirs>=2.5 in c:\\\\programdata\\\\miniconda3\\\\lib\\\\site-packages (from jupyter-core!=5.0.*,>=4.12->nbformat) (3.10.0)\\nRequirement already satisfied: pywin32>=300 in c:\\\\programdata\\\\miniconda3\\\\lib\\\\site-packages (from jupyter-core!=5.0.*,>=4.12->nbformat) (307)\\nDownloading nbformat-5.10.4-py3-none-any.whl (78 kB)\\nDownloading fastjsonschema-2.21.1-py3-none-any.whl (23 kB)\\nDownloading jsonschema-4.23.0-py3-none-any.whl (88 kB)\\nDownloading attrs-24.2.0-py3-none-any.whl (63 kB)\\nDownloading jsonschema_specifications-2024.10.1-py3-none-any.whl (18 kB)\\nDownloading referencing-0.35.1-py3-none-any.whl (26 kB)\\nDownloading rpds_py-0.22.1-cp312-cp312-win_amd64.whl (235 kB)\\nInstalling collected packages: fastjsonschema, rpds-py, attrs, referencing, jsonschema-specifications, jsonschema, nbformat\\nSuccessfully installed attrs-24.2.0 fastjsonschema-2.21.1 jsonschema-4.23.0 jsonschema-specifications-2024.10.1 nbformat-5.10.4 referencing-0.35.1 rpds-py-0.22.1\\nNote: you may need to restart the kernel to use updated packages.\\n'}, {'name': 'stderr', 'output_type': 'stream', 'text': \"  WARNING: The script jsonschema.exe is installed in 'C:\\\\Users\\\\H3C\\\\AppData\\\\Roaming\\\\Python\\\\Python312\\\\Scripts' which is not on PATH.\\n  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.\\n  WARNING: The script jupyter-trust.exe is installed in 'C:\\\\Users\\\\H3C\\\\AppData\\\\Roaming\\\\Python\\\\Python312\\\\Scripts' which is not on PATH.\\n  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.\\n\"}], 'source': '%pip install nbformat'}, {'cell_type': 'code', 'execution_count': 27, 'metadata': {}, 'outputs': [{'ename': 'ModuleNotFoundError', 'evalue': \"No module named 'nbformat'\", 'output_type': 'error', 'traceback': ['\\x1b[1;31m---------------------------------------------------------------------------\\x1b[0m', '\\x1b[1;31mModuleNotFoundError\\x1b[0m                       Traceback (most recent call last)', \"Cell \\x1b[1;32mIn[27], line 1\\x1b[0m\\n\\x1b[1;32m----> 1\\x1b[0m \\x1b[38;5;28;01mimport\\x1b[39;00m \\x1b[38;5;21;01mnbformat\\x1b[39;00m\\n\\x1b[0;32m      3\\x1b[0m \\x1b[38;5;66;03m# 读取Notebook文件\\x1b[39;00m\\n\\x1b[0;32m      4\\x1b[0m \\x1b[38;5;28;01mwith\\x1b[39;00m \\x1b[38;5;28mopen\\x1b[39m(\\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124mtestgit.ipynb\\x1b[39m\\x1b[38;5;124m'\\x1b[39m, \\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124mr\\x1b[39m\\x1b[38;5;124m'\\x1b[39m, encoding\\x1b[38;5;241m=\\x1b[39m\\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124mutf-8\\x1b[39m\\x1b[38;5;124m'\\x1b[39m) \\x1b[38;5;28;01mas\\x1b[39;00m f:\\n\", \"\\x1b[1;31mModuleNotFoundError\\x1b[0m: No module named 'nbformat'\"]}], 'source': \"import nbformat\\n\\n# 读取Notebook文件\\nwith open('testgit.ipynb', 'r', encoding='utf-8') as f:\\n    notebook = nbformat.read(f, as_version=4)\\n\\n# 打印Notebook的JSON结构\\nprint(notebook)\\n\\n# 你可以在这里修改notebook对象，然后保存回文件\\n# ...\\n\\n# 保存修改后的Notebook\\nwith open('modified_notebook.ipynb', 'w', encoding='utf-8') as f:\\n    nbformat.write(notebook, f)\"}, {'cell_type': 'markdown', 'metadata': {}, 'source': \"### 函数和方法\\n<table><tr>\\n<th>函数</th><th>返回值 ( 描述 )</th></tr>\\n<tr><td><a> dict.keys() </a></td><td>返回所有键信息 </td></tr>\\n<tr><td><a> dict.values() </a></td><td>返回所有值信息 </td></tr>\\n<tr><td><a> dict.items() </a></td><td>返回所有键值对 </td></tr>\\n<tr><td><a> dict.get('key',default) </a></td><td>键存在则返回相应值，否则返回默认值 </td></tr>\\n<tr><td><a> dict.pop('key',default) </a></td><td> 键存在则返回相应值，否则删除删除键值对，返回默认值</td></tr>\\n<tr><td><a> dict.popitem() </a></td><td>随机从字典中取出一个键值对 </td></tr>\\n<tr><td><a> dict.clear() </a></td><td>删除所有的键值对 </td></tr>\\n<tr><td><a> del dict['key'] </a></td><td>删除字典中某一个键值对 </td></tr>\\n<tr><td><a> key in dict </a></td><td>如果键在字典中则返回True，否则返回False </td></tr>\\n</table>\"}, {'cell_type': 'code', 'execution_count': 1, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"dict_items([('brand', 'Ford'), ('model', 'Mustang'), ('year', 2018)])\\n\"}], 'source': \"\\ncar = {\\n  'brand': 'Ford',\\n  'model': 'Mustang',\\n  'year': 1964\\n}\\nx = car.items()\\ncar['year'] = 2018\\nprint(x)\"}, {'cell_type': 'code', 'execution_count': 2, 'metadata': {}, 'outputs': [{'data': {'text/plain': \"dict_keys(['brand', 'model', 'year'])\"}, 'execution_count': 2, 'metadata': {}, 'output_type': 'execute_result'}], 'source': 'car.keys()'}, {'cell_type': 'code', 'execution_count': 60, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': '3\\n'}], 'source': \"x = True\\ncountry_counter = {}\\n\\ndef addone(country):\\n    if country in country_counter:\\n        country_counter[country] += 1\\n    else:\\n        country_counter[country] = 1\\n\\naddone('China')\\naddone('Japan')\\naddone('china')\\n\\nprint(len(country_counter))\\n\"}], 'metadata': {'kernelspec': {'display_name': 'base', 'language': 'python', 'name': 'python3'}, 'language_info': {'codemirror_mode': {'name': 'ipython', 'version': 3}, 'file_extension': '.py', 'mimetype': 'text/x-python', 'name': 'python', 'nbconvert_exporter': 'python', 'pygments_lexer': 'ipython3', 'version': '3.12.3'}}, 'nbformat': 4, 'nbformat_minor': 2}\n"
     ]
    }
   ],
   "source": [
    "import nbformat\n",
    "\n",
    "# 读取Notebook文件\n",
    "with open('第三课_Python进阶组合数据类型.ipynb', 'r', encoding='utf-8') as f:\n",
    "    notebook = nbformat.read(f, as_version=4)\n",
    "\n",
    "# 打印Notebook的JSON结构\n",
    "print(notebook)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(notebook.items())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'cell_type': 'markdown', 'metadata': {}, 'source': '<img src=\".\\\\\\\\diyLogo.png\" alt=\"some_text\">\\n<h1> 第三讲 程序设计基础</h1>\\n<a id=backup></a>\\n<H2>目录</H2>  \\n\\n[3.1 组合数据类型概述](#Section1)  \\n[3.2 序列类型](#Section2)  \\n[3.3 集合类型](#Section3)     \\n[3.4 映射类型](#Section4)  '}\n",
      "{'cell_type': 'markdown', 'metadata': {}, 'source': '<a id = Section1> </a>\\n## 3.1 组合数据类型概述\\n'}\n",
      "{'cell_type': 'markdown', 'metadata': {}, 'source': '<a id = Section2> </a>\\n## 3.2 序列类型\\n### 字符串\\n### 元组\\n### 列表\\n\\n<p><a href=\"https://yanghailin.blog.csdn.net/article/details/81126087?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-5.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-5.no_search_link\">\\nthis is example of python</a></p'}\n",
      "{'cell_type': 'markdown', 'metadata': {}, 'source': '### 3.2.1字符串运算\\n\\n'}\n",
      "{'cell_type': 'code', 'execution_count': 1, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': 'a + b 输出结果： HelloPython\\na * 2 输出结果： HelloHello\\na[1] 输出结果： e\\na[1:4] 输出结果： ell\\nH 在变量 a 中\\nM 不在变量 a 中\\n\\\\n\\n\\\\n\\n'}], 'source': 'a = \"Hello\"\\nb = \"Python\"\\n \\nprint(\"a + b 输出结果：\", a + b)\\nprint(\"a * 2 输出结果：\", a * 2)\\nprint(\"a[1] 输出结果：\", a[1])\\nprint(\"a[1:4] 输出结果：\", a[1:4])\\n# in \\nif( \"H\" in a) :\\n    print(\"H 在变量 a 中\")\\nelse :\\n    print(\"H 不在变量 a 中\")\\n#not in \\nif( \"M\" not in a) :\\n    print(\"M 不在变量 a 中\")\\nelse :\\n    print(\"M 在变量 a 中\")\\n# r R 直接打印字符串 \\nprint (r\\'\\\\n\\')\\nprint (R\\'\\\\n\\')'}\n",
      "{'cell_type': 'markdown', 'metadata': {}, 'source': '### 3.2.2元组\\nPython 的元组与列表类似，不同之处在于元组的元素不能修改,可以合并。\\n\\n元组使用小括号 ( )，列表使用方括号 [ ]。\\n\\n元组创建很简单，只需要在括号中添加元素，并使用逗号隔开即可。'}\n",
      "{'cell_type': 'code', 'execution_count': 3, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"('Google', 'Runoob', 1997, 2000) \\n tup2 \\n ('a', 'b', 'c', 'd') \\n <class 'tuple'>\\n\"}, {'data': {'text/plain': \"'Google'\"}, 'execution_count': 3, 'metadata': {}, 'output_type': 'execute_result'}], 'source': 'tup1 = (\\'Google\\', \\'Runoob\\', 1997, 2000)\\ntup2 = (1, 2, 3, 4, 5 )\\ntup3 = \"a\", \"b\", \"c\", \"d\"   #  不需要括号也可以\\ntype(tup3)\\nprint(tup1,\"\\\\n\",\"tup2\",\"\\\\n\",tup3,\"\\\\n\",type(tup3))\\ntup1[0]'}\n",
      "{'cell_type': 'code', 'execution_count': 28, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': '2448321434544\\n2448321266176\\n'}], 'source': 'print(id(tup1))\\ntup1=1,2,3\\nprint(id(tup1))\\n'}\n",
      "{'cell_type': 'markdown', 'metadata': {}, 'source': '### 3.2.3列表\\n序列是 Python 中最基本的数据结构。\\n\\n序列中的每个值都有对应的位置值，称之为索引，第一个索引是 0，第二个索引是 1，依此类推。\\n\\nPython 有 6 个序列的内置类型，但最常见的是列表和元组。\\n\\n列表都可以进行的操作包括索引，切片，加，乘，检查成员。\\n\\n此外，Python 已经内置确定序列的长度以及确定最大和最小的元素的方法。\\n\\n列表是最常用的 Python 数据类型，它可以作为一个方括号内的逗号分隔值出现。\\n\\n列表的数据项不需要具有相同的类型\\n\\n创建一个列表，只要把逗号分隔的不同的数据项使用方括号括起来即可。如下所示：'}\n",
      "{'cell_type': 'code', 'execution_count': 1, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': 'red\\nwhite\\nblack\\n'}], 'source': \"list1 = ['red', 'green', 'blue', 'yellow', 'white', 'black']\\nprint( list1[0] )\\nprint( list1[-2] )\\nprint( list1[-1] )\\nlist1[0]='lightred'\"}\n",
      "{'cell_type': 'code', 'execution_count': 13, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"list[0]:  Google\\nlist[0:4]:  ['Google', 'Runoob', 'Zhihu', 'Taobao', 'Wiki']\\n\"}], 'source': 'list = [\\'Google\\', \\'Runoob\\', \"Zhihu\", \"Taobao\", \"Wiki\"]\\n \\n# 读取第二位\\nprint (\"list[0]: \", list[0])\\n# 从第二位开始（包含）截取到倒数第二位（不包含）\\nprint (\"list[0:4]: \", list[0:5])'}\n",
      "{'cell_type': 'code', 'execution_count': 16, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"更新后的第三个元素为 :  ['x', 'a', 2001, 'a', 't']\\n更新后的列表 :  ['x', 'a', 2001, 'a', 't', 'Baidu']\\n\"}], 'source': '#\\nlist[2] = 2001\\nprint (\"更新后的第三个元素为 : \", list)\\n \\nlist.append(\\'Baidu\\')\\nprint (\"更新后的列表 : \", list)\\n\\nlist[:]=\\'\\''}\n",
      "{'cell_type': 'code', 'execution_count': 17, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': '[]\\n'}], 'source': 'print(list)'}\n",
      "{'cell_type': 'code', 'execution_count': None, 'metadata': {}, 'outputs': [], 'source': '#删除元素\\ndel list[2]\\nprint (\"删除第三个元素 : \", list)'}\n",
      "{'cell_type': 'markdown', 'metadata': {}, 'source': '### Python列表函数&方法\\nPython包含以下函数:\\n<table><tr>\\n<th style=\"width:5%\">序号</th><th style=\"width:95%\">函数</th></tr>\\n\\n<tr><td>1</td><td><a href=\"python3-att-list-len.html\">len(list)</a><br>列表元素个数</td></tr>\\n<tr><td>2</td><td><a href=\"python3-att-list-max.html\">max(list)</a><br>返回列表元素最大值</td></tr>\\n<tr><td>3</td><td><a href=\"python3-att-list-min.html\">min(list)</a><br>返回列表元素最小值</td></tr>\\n<tr><td>4</td><td><a href=\"python3-att-list-list.html\">list(seq)</a><br>将元组转换为列表</td></tr>\\n</table>\\n\\nPython包含以下方法:\\n<table><tr>\\n<th style=\"width:5%\">序号</th><th style=\"width:95%\">方法</th></tr>\\n<tr><td>1</td><td><a href=\"python3-att-list-append.html\">list.append(obj)</a><br>在列表末尾添加新的对象</td></tr>\\n<tr><td>2</td><td><a href=\"python3-att-list-count.html\">list.count(obj)</a><br>统计某个元素在列表中出现的次数</td></tr>\\n<tr><td>3</td><td><a href=\"python3-att-list-extend.html\">list.extend(seq)</a><br>在列表末尾一次性追加另一个序列中的多个值（用新列表扩展原来的列表）</td></tr>\\n<tr><td>4</td><td><a href=\"python3-att-list-index.html\">list.index(obj)</a><br>从列表中找出某个值第一个匹配项的索引位置</td></tr>\\n<tr><td>5</td><td><a href=\"python3-att-list-insert.html\">list.insert(index, obj)</a><br>将对象插入列表</td></tr>\\n<tr><td>6</td><td><a href=\"python3-att-list-pop.html\">list.pop([index=-1])</a><br>移除列表中的一个元素（默认最后一个元素），并且返回该元素的值</td></tr>\\n<tr><td>7</td><td><a href=\"python3-att-list-remove.html\">list.remove(obj)</a><br>移除列表中某个值的第一个匹配项</td></tr>\\n<tr><td>8</td><td><a href=\"python3-att-list-reverse.html\">list.reverse()</a><br>反向列表中元素</td></tr>\\n<tr><td>9</td><td><a href=\"python3-att-list-sort.html\">\\tlist.sort( key=None, reverse=False)</a><br>对原列表进行排序</td></tr>\\n<tr><td>10</td><td><a href=\"python3-att-list-clear.html\">list.clear()</a><br>清空列表</td></tr>\\n<tr><td>11</td><td><a href=\"python3-att-list-copy.html\">list.copy()</a><br>复制列表</td></tr>\\n</table>\\n'}\n",
      "{'cell_type': 'code', 'execution_count': 27, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"['Mitsubishi', 'Ford', 'BMW', 'VW']\\n\"}], 'source': \"# A function that returns the length of the value:\\ndef myFunc(e):\\n  return len(e)\\ncars = ['Ford', 'Mitsubishi', 'BMW', 'VW']\\ncars.sort(reverse=True, key=myFunc)\\nprint(cars)\"}\n",
      "{'cell_type': 'code', 'execution_count': 28, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"['Mitsubishi', 'Ford', 'BMW']\\n\"}], 'source': 'cars.pop()\\nprint(cars)\\n'}\n",
      "{'cell_type': 'markdown', 'metadata': {}, 'source': '<a id=Section3></a>\\n## 3.3 集合类型\\n集合（set）是一个无序的不重复元素序列。\\n\\n可以使用大括号 { } 或者 set() 函数创建集合，注意：创建一个空集合必须用 set() 而不是 { }，因为 { } 是用来创建一个空字典。'}\n",
      "{'cell_type': 'markdown', 'metadata': {}, 'source': '### 3.3.1基本操作：'}\n",
      "{'cell_type': 'code', 'execution_count': None, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': '4\\n'}, {'ename': 'TypeError', 'evalue': \"'set' object is not subscriptable\", 'output_type': 'error', 'traceback': ['\\x1b[1;31m---------------------------------------------------------------------------\\x1b[0m', '\\x1b[1;31mTypeError\\x1b[0m                                 Traceback (most recent call last)', \"Cell \\x1b[1;32mIn[4], line 3\\x1b[0m\\n\\x1b[0;32m      1\\x1b[0m basket \\x1b[38;5;241m=\\x1b[39m {\\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124mapple\\x1b[39m\\x1b[38;5;124m'\\x1b[39m, \\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124morange\\x1b[39m\\x1b[38;5;124m'\\x1b[39m, \\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124mapple\\x1b[39m\\x1b[38;5;124m'\\x1b[39m, \\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124mpear\\x1b[39m\\x1b[38;5;124m'\\x1b[39m, \\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124morange\\x1b[39m\\x1b[38;5;124m'\\x1b[39m, \\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124mbanana\\x1b[39m\\x1b[38;5;124m'\\x1b[39m}\\n\\x1b[0;32m      2\\x1b[0m \\x1b[38;5;28mprint\\x1b[39m(\\x1b[38;5;28mlen\\x1b[39m(basket))                      \\x1b[38;5;66;03m# 这里演示的是去重功能\\x1b[39;00m\\n\\x1b[1;32m----> 3\\x1b[0m \\x1b[43mbasket\\x1b[49m\\x1b[43m[\\x1b[49m\\x1b[38;5;241;43m0\\x1b[39;49m\\x1b[43m]\\x1b[49m\\n\", \"\\x1b[1;31mTypeError\\x1b[0m: 'set' object is not subscriptable\"]}], 'source': \"basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}\\nprint(len(basket))                      # 这里演示的是去重功能\\nbasket[0] #不能索引\"}\n",
      "{'cell_type': 'code', 'execution_count': 2, 'metadata': {}, 'outputs': [{'data': {'text/plain': 'True'}, 'execution_count': 2, 'metadata': {}, 'output_type': 'execute_result'}], 'source': \"{'orange', 'banana', 'pear', 'apple'}\\n'orange' in basket                 # 快速判断元素是否在集合内\"}\n",
      "{'cell_type': 'code', 'execution_count': 3, 'metadata': {}, 'outputs': [{'data': {'text/plain': 'False'}, 'execution_count': 3, 'metadata': {}, 'output_type': 'execute_result'}], 'source': \"'crabgrass' in basket\"}\n",
      "{'cell_type': 'code', 'execution_count': 32, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"a= {'d', 'c', 'r', 'a', 'b'}\\nb= {'z', 'm', 'c', 'l', 'a'}\\n\"}, {'data': {'text/plain': \"{'b', 'd', 'r'}\"}, 'execution_count': 32, 'metadata': {}, 'output_type': 'execute_result'}], 'source': \"# 下面展示两个集合间的运算.\\na = set('abracadabra')\\nb = set('alacazam')\\nprint('a=',a)\\nprint('b=',b)\\n# 集合a中包含而集合b中不包含的元素                                 \\na - b                              \"}\n",
      "{'cell_type': 'code', 'execution_count': 7, 'metadata': {}, 'outputs': [{'data': {'text/plain': \"{'a', 'b', 'c', 'd', 'l', 'm', 'r', 'z'}\"}, 'execution_count': 7, 'metadata': {}, 'output_type': 'execute_result'}], 'source': '# 集合a或b中包含的所有元素（并集）\\na | b                              '}\n",
      "{'cell_type': 'code', 'execution_count': 8, 'metadata': {}, 'outputs': [{'data': {'text/plain': \"{'a', 'c'}\"}, 'execution_count': 8, 'metadata': {}, 'output_type': 'execute_result'}], 'source': '# 集合a和b中都包含了的元素(交集)\\na & b                              '}\n",
      "{'cell_type': 'code', 'execution_count': 9, 'metadata': {}, 'outputs': [{'data': {'text/plain': \"{'b', 'd', 'l', 'm', 'r', 'z'}\"}, 'execution_count': 9, 'metadata': {}, 'output_type': 'execute_result'}], 'source': '# 不同时包含于a和b的元素（交集的补集）\\na ^ b                              '}\n",
      "{'cell_type': 'code', 'execution_count': 5, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"{'d', 'r'}\\n\"}], 'source': \"#类似列表推导式，同样集合支持集合推导式(Set comprehension):\\na = {x  for x in 'abracadabra' \\n              if x not in 'abc'}\\nprint(a)\"}\n",
      "{'cell_type': 'markdown', 'metadata': {}, 'source': '### 3.3.2集合运算\\n\\n<table><tr>\\n<th>方法</th>\\n<th>描述</th>\\n</tr>\\n<tr><td><a href=\"ref-set-add.html\" target=\"_blank\" rel=\"noopener noreferrer\">add()</a></td><td>为集合添加元素</td></tr>\\n<tr><td><a href=\"ref-set-clear.html\" target=\"_blank\" rel=\"noopener noreferrer\">clear()</a></td><td>移除集合中的所有元素</td></tr>\\n<tr><td><a href=\"ref-set-copy.html\" target=\"_blank\" rel=\"noopener noreferrer\">copy()</a></td><td>拷贝一个集合</td></tr>\\n  <tr>\\n    <td><a href=\"ref-set-difference.html\" target=\"_blank\" rel=\"noopener noreferrer\">difference()</a></td><td>返回多个集合的差集</td>\\n  </tr>\\n  <tr>\\n    <td><a href=\"ref-set-difference_update.html\" target=\"_blank\" rel=\"noopener noreferrer\">difference_update()</a></td><td>移除集合中的元素，该元素在指定的集合也存在。</td>\\n  </tr>\\n<tr><td><a href=\"ref-set-discard.html\" target=\"_blank\" rel=\"noopener noreferrer\">discard()</a></td><td>删除集合中指定的元素</td></tr>\\n  <tr>\\n    <td><a href=\"ref-set-intersection.html\" target=\"_blank\" rel=\"noopener noreferrer\">intersection()</a></td><td>返回集合的交集</td>\\n  </tr>\\n<tr><td><a href=\"ref-set-intersection_update.html\" target=\"_blank\" rel=\"noopener noreferrer\">intersection_update()</a></td><td>\\n  返回集合的交集。</td></tr>\\n  <tr>\\n    <td><a href=\"ref-set-isdisjoint.html\" target=\"_blank\" rel=\"noopener noreferrer\">isdisjoint()</a></td><td>判断两个集合是否包含相同的元素，如果没有返回 True，否则返回 False。</td>\\n  </tr>\\n  <tr>\\n    <td><a href=\"ref-set-issubset.html\" target=\"_blank\" rel=\"noopener noreferrer\">issubset()</a></td><td>判断指定集合是否为该方法参数集合的子集。</td>\\n  </tr>\\n<tr><td><a href=\"ref-set-issuperset.html\" target=\"_blank\" rel=\"noopener noreferrer\">issuperset()</a></td><td>判断该方法的参数集合是否为指定集合的子集</td></tr>\\n<tr><td><a href=\"ref-set-pop.html\" target=\"_blank\" rel=\"noopener noreferrer\">pop()</a></td><td>随机移除元素</td></tr>\\n<tr><td><a href=\"ref-set-remove.html\" target=\"_blank\" rel=\"noopener noreferrer\">remove()</a></td><td>移除指定元素</td></tr>\\n  <tr>\\n    <td><a href=\"ref-set-symmetric_difference.html\" target=\"_blank\" rel=\"noopener noreferrer\">symmetric_difference()</a></td><td>返回两个集合中不重复的元素集合。</td>\\n  </tr>\\n<tr><td><a href=\"ref-set-symmetric_difference_update.html\" target=\"_blank\" rel=\"noopener noreferrer\">symmetric_difference_update()</a></td><td>\\n  移除当前集合中在另外一个指定集合相同的元素，并将另外一个指定集合中不同的元素插入到当前集合中。 </td></tr>\\n  <tr>\\n    <td><a href=\"ref-set-union.html\" target=\"_blank\" rel=\"noopener noreferrer\">union()</a></td><td>返回两个集合的并集</td>\\n  </tr>\\n<tr><td><a href=\"ref-set-update.html\" target=\"_blank\" rel=\"noopener noreferrer\">update()</a></td><td>给集合添加元素</td></tr>\\n</table>'}\n",
      "{'cell_type': 'code', 'execution_count': 52, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"{'Facebook'}\\n{'Facebook', 'o', 'k', 'c', 'e', 'a', 'F', 'b'}\\n{'Facebook', 'o', 'k', 'c', 'e', 'a', 'F', 'b'}\\n\"}, {'data': {'text/plain': \"'Facebook'\"}, 'execution_count': 52, 'metadata': {}, 'output_type': 'execute_result'}], 'source': '# 增加\\nbasket.add(\"Facebook\")\\nprint(basket)\\n# 添加\\nbasket.update(\"Facebook\")\\nprint(basket)\\n# 删除\\n#basket.remove(\"apple\")\\nprint(basket)\\n#basket.remove(\\'none\\')  # throw error!!!\\nbasket.discard(\\'none\\') # don\\'t throw error!!!\\nbasket.pop()# throw one element random'}\n",
      "{'cell_type': 'code', 'execution_count': 53, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"{'k', 'c', 'e', 'a', 'F', 'b'}\\n\"}, {'data': {'text/plain': '6'}, 'execution_count': 53, 'metadata': {}, 'output_type': 'execute_result'}], 'source': '# 计算集合长度\\nbasket.pop()\\nprint(basket)\\nlen(basket)'}\n",
      "{'cell_type': 'code', 'execution_count': 22, 'metadata': {}, 'outputs': [], 'source': '#清理集合\\nbasket.clear()\\n'}\n",
      "{'cell_type': 'markdown', 'metadata': {}, 'source': '<a id=Section4></a>\\n## 3.4 映射类型\\n字典是另一种可变容器模型，且可存储任意类型对象。\\n字典的每个键值 key=>value 对用冒号 : 分割，每个对之间用逗号(,)分割，整个字典包括在花括号 {} 中 ,格式如下所示：\\n'}\n",
      "{'cell_type': 'code', 'execution_count': 1, 'metadata': {}, 'outputs': [{'data': {'image/svg+xml': '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\\n<!-- Generated by graphviz version 7.0.1 (20221109.1506)\\n -->\\n<!-- Title: 顺序结构 Pages: 1 -->\\n<svg width=\"234pt\" height=\"188pt\"\\n viewBox=\"0.00 0.00 234.00 188.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 184)\">\\n<title>顺序结构</title>\\n<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-184 230,-184 230,4 -4,4\"/>\\n<!-- 1 -->\\n<g id=\"node1\" class=\"node\">\\n<title>1</title>\\n<polygon fill=\"none\" stroke=\"black\" points=\"145,-180 91,-180 91,-144 145,-144 145,-180\"/>\\n<text text-anchor=\"middle\" x=\"118\" y=\"-158.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">字典</text>\\n</g>\\n<!-- 2 -->\\n<g id=\"node2\" class=\"node\">\\n<title>2</title>\\n<polygon fill=\"none\" stroke=\"black\" points=\"70,-108 0,-108 0,-72 70,-72 70,-108\"/>\\n<text text-anchor=\"middle\" x=\"35\" y=\"-86.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">name1：</text>\\n</g>\\n<!-- 1&#45;&gt;2 -->\\n<g id=\"edge1\" class=\"edge\">\\n<title>1&#45;&gt;2</title>\\n<path fill=\"none\" stroke=\"black\" d=\"M97.48,-143.7C87.41,-135.2 75.09,-124.81 64.07,-115.51\"/>\\n<polygon fill=\"black\" stroke=\"black\" points=\"66.63,-113.09 56.73,-109.32 62.11,-118.45 66.63,-113.09\"/>\\n</g>\\n<!-- 3 -->\\n<g id=\"node3\" class=\"node\">\\n<title>3</title>\\n<polygon fill=\"none\" stroke=\"black\" points=\"148,-108 88,-108 88,-72 148,-72 148,-108\"/>\\n<text text-anchor=\"middle\" x=\"118\" y=\"-86.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">key2：</text>\\n</g>\\n<!-- 1&#45;&gt;3 -->\\n<g id=\"edge2\" class=\"edge\">\\n<title>1&#45;&gt;3</title>\\n<path fill=\"none\" stroke=\"black\" d=\"M118,-143.7C118,-136.41 118,-127.73 118,-119.54\"/>\\n<polygon fill=\"black\" stroke=\"black\" points=\"121.5,-119.62 118,-109.62 114.5,-119.62 121.5,-119.62\"/>\\n</g>\\n<!-- 4 -->\\n<g id=\"node4\" class=\"node\">\\n<title>4</title>\\n<polygon fill=\"none\" stroke=\"black\" points=\"226,-108 166,-108 166,-72 226,-72 226,-108\"/>\\n<text text-anchor=\"middle\" x=\"196\" y=\"-86.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">key3：</text>\\n</g>\\n<!-- 1&#45;&gt;4 -->\\n<g id=\"edge3\" class=\"edge\">\\n<title>1&#45;&gt;4</title>\\n<path fill=\"none\" stroke=\"black\" d=\"M137.28,-143.7C146.66,-135.28 158.09,-125.02 168.38,-115.79\"/>\\n<polygon fill=\"black\" stroke=\"black\" points=\"170.44,-118.64 175.54,-109.36 165.76,-113.43 170.44,-118.64\"/>\\n</g>\\n<!-- 5 -->\\n<g id=\"node5\" class=\"node\">\\n<title>5</title>\\n<polygon fill=\"none\" stroke=\"black\" points=\"62.5,-36 7.5,-36 7.5,0 62.5,0 62.5,-36\"/>\\n<text text-anchor=\"middle\" x=\"35\" y=\"-14.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">Value1</text>\\n</g>\\n<!-- 2&#45;&gt;5 -->\\n<g id=\"edge4\" class=\"edge\">\\n<title>2&#45;&gt;5</title>\\n<path fill=\"none\" stroke=\"black\" d=\"M35,-71.7C35,-64.41 35,-55.73 35,-47.54\"/>\\n<polygon fill=\"black\" stroke=\"black\" points=\"38.5,-47.62 35,-37.62 31.5,-47.62 38.5,-47.62\"/>\\n</g>\\n<!-- 6 -->\\n<g id=\"node6\" class=\"node\">\\n<title>6</title>\\n<polygon fill=\"none\" stroke=\"black\" points=\"145.5,-36 90.5,-36 90.5,0 145.5,0 145.5,-36\"/>\\n<text text-anchor=\"middle\" x=\"118\" y=\"-14.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">Value2</text>\\n</g>\\n<!-- 3&#45;&gt;6 -->\\n<g id=\"edge5\" class=\"edge\">\\n<title>3&#45;&gt;6</title>\\n<path fill=\"none\" stroke=\"black\" d=\"M118,-71.7C118,-64.41 118,-55.73 118,-47.54\"/>\\n<polygon fill=\"black\" stroke=\"black\" points=\"121.5,-47.62 118,-37.62 114.5,-47.62 121.5,-47.62\"/>\\n</g>\\n<!-- 7 -->\\n<g id=\"node7\" class=\"node\">\\n<title>7</title>\\n<polygon fill=\"none\" stroke=\"black\" points=\"223.5,-36 168.5,-36 168.5,0 223.5,0 223.5,-36\"/>\\n<text text-anchor=\"middle\" x=\"196\" y=\"-14.3\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">Value3</text>\\n</g>\\n<!-- 4&#45;&gt;7 -->\\n<g id=\"edge6\" class=\"edge\">\\n<title>4&#45;&gt;7</title>\\n<path fill=\"none\" stroke=\"black\" d=\"M196,-71.7C196,-64.41 196,-55.73 196,-47.54\"/>\\n<polygon fill=\"black\" stroke=\"black\" points=\"199.5,-47.62 196,-37.62 192.5,-47.62 199.5,-47.62\"/>\\n</g>\\n</g>\\n</svg>\\n', 'text/plain': '<graphviz.graphs.Digraph at 0x1bcf0a8e200>'}, 'execution_count': 1, 'metadata': {}, 'output_type': 'execute_result'}], 'source': '\\nimport graphviz\\ndot=graphviz.Digraph(comment=\\'the round table\\',name=\"顺序结构\",node_attr={\\'shape\\': \\'box\\'})\\ndot.node(\\'1\\',\\'字典\\')\\ndot.node(\\'2\\',\\'name1：\\')\\ndot.node(\\'3\\',\\'key2：\\')\\ndot.node(\\'4\\',\\'key3：\\')\\ndot.node(\\'5\\',\\'Value1\\')\\ndot.node(\\'6\\',\\'Value2\\')\\ndot.node(\\'7\\',\\'Value3\\')\\ndot.edges([\\'12\\',\\'13\\',\\'14\\',\\'25\\',\\'36\\',\\'47\\'])\\ndot'}\n",
      "{'cell_type': 'markdown', 'metadata': {}, 'source': '### 基本操作\\n键必须是唯一的，但值则不必。\\n\\n值可以取任何数据类型，但键必须是不可变的，如字符串，数字。\\n\\n一个简单的字典实例：'}\n",
      "{'cell_type': 'code', 'execution_count': 55, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"{'name': 'zhangsan', 'Age': 20, 'url': 'www.xauat.edu.cn'}\\n\"}], 'source': \"dict = {'name': 'zhangsan', 'Age': 20, 'url': 'www.xauat.edu.cn'}\\nprint(dict)\"}\n",
      "{'cell_type': 'markdown', 'metadata': {}, 'source': '### 访问字典里的值  \\n把相应的键放入到方括号中，如下实例:'}\n",
      "{'cell_type': 'code', 'execution_count': 4, 'metadata': {}, 'outputs': [{'data': {'text/plain': \"'zhangsan'\"}, 'execution_count': 4, 'metadata': {}, 'output_type': 'execute_result'}], 'source': \"dict['name']\"}\n",
      "{'cell_type': 'markdown', 'metadata': {}, 'source': '### 修改字典   \\n向字典添加新内容的方法是增加新的键/值对，修改或删除已有键/值对如下实例:'}\n",
      "{'cell_type': 'code', 'execution_count': 7, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"{'name': '李四', 'Age': 20, 'url': 'www.xauat.edu.cn', 'sex': '男'}\\n\"}], 'source': 'dict[\\'name\\']=\"李四\"\\ndict[\\'sex\\']=\\'男\\'\\nprint(dict)'}\n",
      "{'cell_type': 'code', 'execution_count': 20, 'metadata': {}, 'outputs': [{'data': {'text/plain': \"['c:\\\\\\\\ProgramData\\\\\\\\miniconda3\\\\\\\\Lib\\\\\\\\site-packages\\\\\\\\win32\\\\\\\\lib',\\n 'c:\\\\\\\\ProgramData\\\\\\\\miniconda3\\\\\\\\Lib\\\\\\\\site-packages\\\\\\\\Pythonwin',\\n 'c:\\\\\\\\ProgramData\\\\\\\\miniconda3\\\\\\\\Lib\\\\\\\\site-packages\\\\\\\\win32',\\n 'c:\\\\\\\\ProgramData\\\\\\\\miniconda3\\\\\\\\Lib\\\\\\\\site-packages',\\n 'c:\\\\\\\\ProgramData\\\\\\\\miniconda3\\\\\\\\python312.zip',\\n 'c:\\\\\\\\ProgramData\\\\\\\\miniconda3\\\\\\\\DLLs',\\n 'c:\\\\\\\\ProgramData\\\\\\\\miniconda3\\\\\\\\Lib',\\n 'c:\\\\\\\\ProgramData\\\\\\\\miniconda3',\\n '']\"}, 'execution_count': 20, 'metadata': {}, 'output_type': 'execute_result'}], 'source': 'import sys\\nmypath=sys.path\\ndef myFunc(e):\\n  return len(e)\\n\\nmypath.sort(reverse=True, key=myFunc)\\nlen(mypath)\\nmypath'}\n",
      "{'cell_type': 'code', 'execution_count': 25, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': 'Defaulting to user installation because normal site-packages is not writeable\\nCollecting nbformat\\n  Downloading nbformat-5.10.4-py3-none-any.whl.metadata (3.6 kB)\\nCollecting fastjsonschema>=2.15 (from nbformat)\\n  Downloading fastjsonschema-2.21.1-py3-none-any.whl.metadata (2.2 kB)\\nCollecting jsonschema>=2.6 (from nbformat)\\n  Downloading jsonschema-4.23.0-py3-none-any.whl.metadata (7.9 kB)\\nRequirement already satisfied: jupyter-core!=5.0.*,>=4.12 in c:\\\\programdata\\\\miniconda3\\\\lib\\\\site-packages (from nbformat) (5.7.2)\\nRequirement already satisfied: traitlets>=5.1 in c:\\\\programdata\\\\miniconda3\\\\lib\\\\site-packages (from nbformat) (5.14.3)\\nCollecting attrs>=22.2.0 (from jsonschema>=2.6->nbformat)\\n  Downloading attrs-24.2.0-py3-none-any.whl.metadata (11 kB)\\nCollecting jsonschema-specifications>=2023.03.6 (from jsonschema>=2.6->nbformat)\\n  Downloading jsonschema_specifications-2024.10.1-py3-none-any.whl.metadata (3.0 kB)\\nCollecting referencing>=0.28.4 (from jsonschema>=2.6->nbformat)\\n  Downloading referencing-0.35.1-py3-none-any.whl.metadata (2.8 kB)\\nCollecting rpds-py>=0.7.1 (from jsonschema>=2.6->nbformat)\\n  Downloading rpds_py-0.22.1-cp312-cp312-win_amd64.whl.metadata (4.2 kB)\\nRequirement already satisfied: platformdirs>=2.5 in c:\\\\programdata\\\\miniconda3\\\\lib\\\\site-packages (from jupyter-core!=5.0.*,>=4.12->nbformat) (3.10.0)\\nRequirement already satisfied: pywin32>=300 in c:\\\\programdata\\\\miniconda3\\\\lib\\\\site-packages (from jupyter-core!=5.0.*,>=4.12->nbformat) (307)\\nDownloading nbformat-5.10.4-py3-none-any.whl (78 kB)\\nDownloading fastjsonschema-2.21.1-py3-none-any.whl (23 kB)\\nDownloading jsonschema-4.23.0-py3-none-any.whl (88 kB)\\nDownloading attrs-24.2.0-py3-none-any.whl (63 kB)\\nDownloading jsonschema_specifications-2024.10.1-py3-none-any.whl (18 kB)\\nDownloading referencing-0.35.1-py3-none-any.whl (26 kB)\\nDownloading rpds_py-0.22.1-cp312-cp312-win_amd64.whl (235 kB)\\nInstalling collected packages: fastjsonschema, rpds-py, attrs, referencing, jsonschema-specifications, jsonschema, nbformat\\nSuccessfully installed attrs-24.2.0 fastjsonschema-2.21.1 jsonschema-4.23.0 jsonschema-specifications-2024.10.1 nbformat-5.10.4 referencing-0.35.1 rpds-py-0.22.1\\nNote: you may need to restart the kernel to use updated packages.\\n'}, {'name': 'stderr', 'output_type': 'stream', 'text': \"  WARNING: The script jsonschema.exe is installed in 'C:\\\\Users\\\\H3C\\\\AppData\\\\Roaming\\\\Python\\\\Python312\\\\Scripts' which is not on PATH.\\n  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.\\n  WARNING: The script jupyter-trust.exe is installed in 'C:\\\\Users\\\\H3C\\\\AppData\\\\Roaming\\\\Python\\\\Python312\\\\Scripts' which is not on PATH.\\n  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.\\n\"}], 'source': '%pip install nbformat'}\n",
      "{'cell_type': 'code', 'execution_count': 27, 'metadata': {}, 'outputs': [{'ename': 'ModuleNotFoundError', 'evalue': \"No module named 'nbformat'\", 'output_type': 'error', 'traceback': ['\\x1b[1;31m---------------------------------------------------------------------------\\x1b[0m', '\\x1b[1;31mModuleNotFoundError\\x1b[0m                       Traceback (most recent call last)', \"Cell \\x1b[1;32mIn[27], line 1\\x1b[0m\\n\\x1b[1;32m----> 1\\x1b[0m \\x1b[38;5;28;01mimport\\x1b[39;00m \\x1b[38;5;21;01mnbformat\\x1b[39;00m\\n\\x1b[0;32m      3\\x1b[0m \\x1b[38;5;66;03m# 读取Notebook文件\\x1b[39;00m\\n\\x1b[0;32m      4\\x1b[0m \\x1b[38;5;28;01mwith\\x1b[39;00m \\x1b[38;5;28mopen\\x1b[39m(\\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124mtestgit.ipynb\\x1b[39m\\x1b[38;5;124m'\\x1b[39m, \\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124mr\\x1b[39m\\x1b[38;5;124m'\\x1b[39m, encoding\\x1b[38;5;241m=\\x1b[39m\\x1b[38;5;124m'\\x1b[39m\\x1b[38;5;124mutf-8\\x1b[39m\\x1b[38;5;124m'\\x1b[39m) \\x1b[38;5;28;01mas\\x1b[39;00m f:\\n\", \"\\x1b[1;31mModuleNotFoundError\\x1b[0m: No module named 'nbformat'\"]}], 'source': \"import nbformat\\n\\n# 读取Notebook文件\\nwith open('testgit.ipynb', 'r', encoding='utf-8') as f:\\n    notebook = nbformat.read(f, as_version=4)\\n\\n# 打印Notebook的JSON结构\\nprint(notebook)\\n\\n# 你可以在这里修改notebook对象，然后保存回文件\\n# ...\\n\\n# 保存修改后的Notebook\\nwith open('modified_notebook.ipynb', 'w', encoding='utf-8') as f:\\n    nbformat.write(notebook, f)\"}\n",
      "{'cell_type': 'markdown', 'metadata': {}, 'source': \"### 函数和方法\\n<table><tr>\\n<th>函数</th><th>返回值 ( 描述 )</th></tr>\\n<tr><td><a> dict.keys() </a></td><td>返回所有键信息 </td></tr>\\n<tr><td><a> dict.values() </a></td><td>返回所有值信息 </td></tr>\\n<tr><td><a> dict.items() </a></td><td>返回所有键值对 </td></tr>\\n<tr><td><a> dict.get('key',default) </a></td><td>键存在则返回相应值，否则返回默认值 </td></tr>\\n<tr><td><a> dict.pop('key',default) </a></td><td> 键存在则返回相应值，否则删除删除键值对，返回默认值</td></tr>\\n<tr><td><a> dict.popitem() </a></td><td>随机从字典中取出一个键值对 </td></tr>\\n<tr><td><a> dict.clear() </a></td><td>删除所有的键值对 </td></tr>\\n<tr><td><a> del dict['key'] </a></td><td>删除字典中某一个键值对 </td></tr>\\n<tr><td><a> key in dict </a></td><td>如果键在字典中则返回True，否则返回False </td></tr>\\n</table>\"}\n",
      "{'cell_type': 'code', 'execution_count': 1, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': \"dict_items([('brand', 'Ford'), ('model', 'Mustang'), ('year', 2018)])\\n\"}], 'source': \"\\ncar = {\\n  'brand': 'Ford',\\n  'model': 'Mustang',\\n  'year': 1964\\n}\\nx = car.items()\\ncar['year'] = 2018\\nprint(x)\"}\n",
      "{'cell_type': 'code', 'execution_count': 2, 'metadata': {}, 'outputs': [{'data': {'text/plain': \"dict_keys(['brand', 'model', 'year'])\"}, 'execution_count': 2, 'metadata': {}, 'output_type': 'execute_result'}], 'source': 'car.keys()'}\n",
      "{'cell_type': 'code', 'execution_count': 60, 'metadata': {}, 'outputs': [{'name': 'stdout', 'output_type': 'stream', 'text': '3\\n'}], 'source': \"x = True\\ncountry_counter = {}\\n\\ndef addone(country):\\n    if country in country_counter:\\n        country_counter[country] += 1\\n    else:\\n        country_counter[country] = 1\\n\\naddone('China')\\naddone('Japan')\\naddone('china')\\n\\nprint(len(country_counter))\\n\"}\n"
     ]
    }
   ],
   "source": [
    "for ls in notebook['cells']:\n",
    "    print(ls)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cell_type markdown\n",
      "metadata {}\n",
      "source <img src=\".\\\\diyLogo.png\" alt=\"some_text\">\n",
      "<h1> 第三讲 程序设计基础</h1>\n",
      "<a id=backup></a>\n",
      "<H2>目录</H2>  \n",
      "\n",
      "[3.1 组合数据类型概述](#Section1)  \n",
      "[3.2 序列类型](#Section2)  \n",
      "[3.3 集合类型](#Section3)     \n",
      "[3.4 映射类型](#Section4)  \n"
     ]
    }
   ],
   "source": [
    "len(notebook['cells'])\n",
    "for k,v in notebook['cells'][0].items():\n",
    "    print(k,v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# 你可以在这里修改notebook对象，然后保存回文件\n",
    "# ...\n",
    "\n",
    "# 保存修改后的Notebook\n",
    "with open('modified_notebook.ipynb', 'w', encoding='utf-8') as f:\n",
    "    nbformat.write(notebook, f)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 函数和方法\n",
    "<table><tr>\n",
    "<th>函数</th><th>返回值 ( 描述 )</th></tr>\n",
    "<tr><td><a> dict.keys() </a></td><td>返回所有键信息 </td></tr>\n",
    "<tr><td><a> dict.values() </a></td><td>返回所有值信息 </td></tr>\n",
    "<tr><td><a> dict.items() </a></td><td>返回所有键值对 </td></tr>\n",
    "<tr><td><a> dict.get('key',default) </a></td><td>键存在则返回相应值，否则返回默认值 </td></tr>\n",
    "<tr><td><a> dict.pop('key',default) </a></td><td> 键存在则返回相应值，否则删除删除键值对，返回默认值</td></tr>\n",
    "<tr><td><a> dict.popitem() </a></td><td>随机从字典中取出一个键值对 </td></tr>\n",
    "<tr><td><a> dict.clear() </a></td><td>删除所有的键值对 </td></tr>\n",
    "<tr><td><a> del dict['key'] </a></td><td>删除字典中某一个键值对 </td></tr>\n",
    "<tr><td><a> key in dict </a></td><td>如果键在字典中则返回True，否则返回False </td></tr>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_items([('brand', 'Ford'), ('model', 'Mustang'), ('year', 2018)])\n"
     ]
    }
   ],
   "source": [
    "\n",
    "car = {\n",
    "  'brand': 'Ford',\n",
    "  'model': 'Mustang',\n",
    "  'year': 1964\n",
    "}\n",
    "x = car.items()\n",
    "car['year'] = 2018\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['brand', 'model', 'year'])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "car.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "x = True\n",
    "country_counter = {}\n",
    "\n",
    "def addone(country):\n",
    "    if country in country_counter:\n",
    "        country_counter[country] += 1\n",
    "    else:\n",
    "        country_counter[country] = 1\n",
    "\n",
    "addone('China')\n",
    "addone('Japan')\n",
    "addone('china')\n",
    "\n",
    "print(len(country_counter))\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
